Running unary operation instructions for processing vectors

ABSTRACT

During operation, a processor generates a result vector. In particular, the processor records a value from an element at a key element position in an input vector into a base value. Next, for each active element in the result vector to the right of the key element position, the processor generates a result vector by setting the element in the result vector equal to a result of performing a unary operation on the base value a number of times equal to a number of relevant elements. The number of relevant elements is determined from the key element position to and including a predetermined element in the result vector, where the predetermined element in the result vector may be one of: a first element to the left of the element in the result vector; or the element in the result vector.

RELATED APPLICATIONS

This application is a continuation in part of, and hereby claimspriority under 35 U.S.C. §120 to, pending U.S. patent application Ser.No. 12/541,546, entitled “Running-Shift Instructions for ProcessingVectors,” by inventors Jeffry E. Gonion and Keith E. Diefendorff, filed14 Aug. 2009, attorney docket no. APL-P7038US9. This application alsoclaims priority under 35 U.S.C. §120 to U.S. provisional patentapplication No. 61/089,251, attorney docket no. APL-P7038PRV1, entitled“Macroscalar Processor Architecture,” by inventor Jeffry E. Gonion,filed 15 Aug. 2008, to which the parent application Ser. No. 12/541,546also claims priority.

This application is related to: (1) pending application Ser. No.12/419,629, attorney docket no. APL-P7038US1, entitled “Method andApparatus for Executing Program Code,” by inventors Jeffry E. Gonion andKeith E. Diefendorff, filed on 7 Apr. 2009; (2) pending application Ser.No. 12/419,644, attorney docket no. APL-P7038US2, entitled “Break,Pre-Break, and Remaining Instructions for Processing Vectors,” byinventors Jeffry E. Gonion and Keith E. Diefendorff, filed on 7 Apr.2009; (3) pending application Ser. No. 12/419,661, attorney docket no.APL-P7038US3, entitled “Check-Hazard Instructions for ProcessingVectors,” by inventors Jeffry E. Gonion and Keith E. Diefendorff, filedon 7 Apr. 2009; (4) pending application Ser. No. 12/495,656, attorneydocket no. APL-P7038US4, entitled “Copy-Propagate, Propagate-Post, andPropagate-Prior Instructions For Processing Vectors,” by inventorsJeffry E. Gonion and Keith E. Diefendorff, filed on 30 Jun. 2009; (5)pending application Ser. No. 12/495,643, attorney docket no.APL-P7038US5, entitled “Shift-In-Right Instructions for ProcessingVectors,” by inventors Jeffry E. Gonion and Keith E. Diefendorff, filedon 30 Jun. 2009; (6) pending application Ser. No. 12/495,631, attorneydocket no. APL-P7038US6, entitled “Increment-Propagate andDecrement-Propagate Instructions for Processing Vectors,” by inventorsJeffry E. Gonion and Keith E. Diefendorff, filed on 30 Jun. 2009; (7)pending application Ser. No. 12/541,505, attorney docket no.APL-P7038US7, entitled “Running-Sum Instructions for ProcessingVectors,” by inventors Jeffry E. Gonion and Keith E. Diefendorff, filedon 14 Aug. 2009; and (8) pending application Ser. No. 12/541,526,attorney docket no. APL-P7038US8, entitled “Running-AND, Running-OR,Running-XOR, and Running-Multiply Instructions for Processing Vectors”by inventors Jeffry E. Gonion and Keith E. Diefendorff, filed on 14 Aug.2009.

This application is also related to: (1) pending application Ser. No.12/873,043, attorney docked no. APL-P7038USX1, entitled “Running-Min andRunning-Max Instructions for Processing Vectors,” by inventors Jeffry E.Gonion and Keith E. Diefendorff, filed 31 Aug. 2010; (2) pendingapplication Ser. No. 12/873,063, attorney docked no. APL-P7038USX2,entitled “Non-Faulting and First-Faulting Instructions for ProcessingVectors,” by inventors Jeffry E. Gonion and Keith E. Diefendorff, filed31 Aug. 2010; (3) pending application Ser. No. 12/873,074, attorneydocket no. APL-P7038USX3, entitled “Vector Test Instruction forProcessing Vectors” by inventors Jeffry E. Gonion and Keith E.Diefendorff, filed 31 Aug. 2010; (4) pending application Ser. No.12/907,471, attorney docket no. APL-P7038USX4, entitled “Select Firstand Select Last Instructions for Processing Vectors,” by inventorsJeffry E. Gonion and Keith E. Diefendorff, filed 19 Oct. 2010; (5)pending application Ser. No. 12/907,490, attorney docket no.APL-P7038USX5, entitled “Actual Instruction and Actual-FaultInstructions for Processing Vectors,” by inventors Jeffry E. Gonion andKeith E. Diefendorff, filed 19 Oct. 2010; (6) pending application Ser.No. 12/977,333, attorney docket no. APL-P7038USX6, entitled “RemainingInstruction for Processing Vectors,” by inventors Jeffry E. Gonion andKeith E. Diefendorff, filed 23 Dec. 2010; (7) pending application Ser.No. 13/006,243, attorney docket no. APL-P7038USX7, entitled “RemainingInstruction for Processing Vectors,” by inventors Jeffry E. Gonion andKeith E. Diefendorff, filed 13 Jan. 2011; (8) pending application Ser.No. 13/188,737, attorney docket no. APL-P7038USX9, entitled “RunningSubtract and Running Divide Instructions for Processing Vectors” byinventors Jeffry E. Gonion and Keith E. Diefendorff, filed on 22 Jul.2011; (9) pending application Ser. No. 13/291,931, attorney docket no.APL-P7038USX10, entitled “Vector Index Instruction for ProcessingVectors” by inventor Jeffry E. Gonion, filed on 8 Nov. 2011; (10)pending application Ser. No. 13/343,619, attorney docket no.APL-P7038USX11, entitled “Predicate Count and Segment Count Instructionsfor Processing Vectors” by inventor Jeffry E. Gonion, filed on 4 Jan.2012; and (11) pending application Ser. No. 13/414,606, attorney docketno. APL-P7038USX12, entitled “Predicting Branches for VectorPartitioning Loops when Processing Vector Instructions” by inventorJeffry E. Gonion, filed on 7 Mar. 2012.

This application is also related to: (1) pending application Ser. No.12/237,212, attorney docket no. APL-P6031US1, entitled “ConditionalData-Dependency Resolution in Vector Processors,” by inventors Jeffry E.Gonion and Keith E. Diefendorff, filed 24 Sep. 2008; (2) pendingapplication Ser. No. 12/237,196, attorney docket no. APL-P6031US2,entitled “Generating Stop Indicators Based on Conditional DataDependency in Vector Processors,” by inventors Jeffry E. Gonion andKeith E. Diefendorff, filed 24 Sep. 2008; and (3) pending applicationSer. No. 12/237,190, attorney docket no. APL-P6031US3, entitled“Generating Predicate Values Based on Conditional Data Dependency inVector Processors,” by inventors Jeffry E. Gonion and Keith E.Diefendorff, filed 24 Sep. 2008.

BACKGROUND

1. Field

The described embodiments relate to techniques for improving theperformance of computer systems. More specifically, the describedembodiments relate to running unary operation instructions forprocessing vectors.

2. Related Art

Recent advances in processor design have led to the development of anumber of different processor architectures. For example, processordesigners have created superscalar processors that exploitinstruction-level parallelism (ILP), multi-core processors that exploitthread-level parallelism (TLP), and vector processors that exploitdata-level parallelism (DLP). Each of these processor architectures hasunique advantages and disadvantages which have either encouraged orhampered the widespread adoption of the architecture. For example,because ILP processors can often operate on existing program code thathas undergone only minor modifications, these processors have achievedwidespread adoption. However, TLP and DLP processors typically requireapplications to be manually re-coded to gain the benefit of theparallelism that they offer, a process that requires extensive effort.Consequently, TLP and DLP processors have not gained widespread adoptionfor general-purpose applications.

One significant issue affecting the adoption of DLP processors is thevectorization of loops in program code. In a typical program, a largeportion of execution time is spent in loops. Unfortunately, many ofthese loops have characteristics that render them unvectorizable inexisting DLP processors. Thus, the performance benefits gained fromattempting to vectorize program code can be limited.

One significant obstacle to vectorizing loops in program code inexisting systems is dependencies between iterations of the loop. Forexample, loop-carried data dependencies and memory-address aliasing aretwo such dependencies. These dependencies can be identified by acompiler during the compiler's static analysis of program code, but theycannot be completely resolved until runtime data is available. Thus,because the compiler cannot conclusively determine that runtimedependencies will not be encountered, the compiler cannot vectorize theloop. Hence, because existing systems require that the compilerdetermine the extent of available parallelism during compilation,relatively little code can be vectorized.

SUMMARY

The described embodiments provide a processor (e.g., processor 102) forgenerating a result vector with values determined by performing unaryoperations on an element from an input vector. During operation, theprocessor receives the input vector, and a control vector, andoptionally receives a predicate vector. The processor then records avalue from an element at a key element position in the input vector intoa base value. Next, the processor generates a result vector. Whengenerating the result vector, if the predicate vector is received, foreach element in the result vector to the right of the key elementposition for which a corresponding element in the predicate vectorcontains an active value, otherwise, for each element in the resultvector to the right of the key element position, the processor isconfigured to: determine a number of relevant elements from the keyelement position to and including a predetermined element in the resultvector; and set the element in the result vector equal to a result ofperforming a unary operation on the base value a number of times equalto the number of relevant elements.

Note that the unary operation may be one of: a bitwise inversion,negation, a logical NOT, or another unary operation.

In some embodiments, when generating the result vector, the processor isconfigured to set the element in the result vector at the key elementposition equal to one of: (1) the base value; or (2) a result ofperforming the unary operation on the base value once.

In some embodiments, the predetermined element in the result vector maybe one of: (1) a first element to the left of the element in the resultvector; or (2) the element in the result vector.

In some embodiments, if the predicate vector is received, the keyelement position is a leftmost element position where both the controlvector and the predicate vector are active. Otherwise, the key elementposition is a leftmost active element in the control vector.

In some embodiments, if the predicate vector is received, for eachelement in the result vector to the left of the key element position forwhich a corresponding element in the predicate vector is active,otherwise, for each element in the result vector to the left of the keyelement position in the result vector, when generating the resultvector, the processor is configured to set the element in the resultvector equal to a value in a corresponding element in the input vector.However, if no key element position exists, and if the predicate vectoris received, for each element in the result vector for which acorresponding element in the predicate vector is active, otherwise, foreach element in the result vector, when generating the result vector,the processor is configured to set each element in the result vectorequal to a value in a corresponding element in the input vector.

In some embodiments, if the predicate vector is received, whengenerating the result vector, the processor is configured, for eachelement in the result vector, if a corresponding element in thepredicate vector is inactive, to perform one of: (1) leaving the elementin the result vector unmodified; or (2) setting the element in theresult vector to zero.

In some embodiments, if the predicate vector is received, a relevantelement in the result vector is an element in the result vector forwhich the corresponding element in the predicate vector and thecorresponding element in the control vector are active. Otherwise, arelevant element in the result vector is an element in the result vectorfor which the corresponding element in the control vector is active.

In some embodiments, when generating the result vector, the processor isconfigured to process elements in the input vector, the control vector,and, if the predicate vector is received, the predicate vector inparallel to enable the elements of the result vector to be generated inparallel.

Another embodiment provides a method for generating the result vectorusing the processor.

Another embodiment provides a computer system that includes theprocessor.

BRIEF DESCRIPTION OF THE FIGURES

FIG. 1 presents a block diagram of a computer system in accordance withthe described embodiments.

FIG. 2 presents an expanded view of a processor in accordance with thedescribed embodiments.

FIG. 3 presents an expanded view of a vector execution unit inaccordance with the described embodiments.

FIG. 4 presents an example of the parallelization of a loop in programcode in accordance with the described embodiments.

FIG. 5 presents two tables illustrating operation using vectorized codein accordance with the described embodiments.

FIG. 6 presents vectorized program code in accordance with the describedembodiments.

FIGS. 7A-7B present exemplary vectorized program code in accordance withthe described embodiments.

FIG. 8 presents a vectorized loop from program code with memory aliasingin accordance with the described embodiments.

FIG. 9 presents a vectorized loop from program code with memory aliasingin accordance with the described embodiments.

FIG. 10 presents a vectorized loop from program code with pseudoloop-carried dependencies in accordance with the described embodiments.

FIG. 11 presents a vectorized loop from program code with conditionalupdates in accordance with the described embodiments.

FIG. 12 presents a section of source code in accordance with thedescribed embodiments.

FIGS. 13A-13B present a vectorized loop from program code withconsolidation in accordance with the described embodiments.

FIG. 14 presents an example loop from program code and a dependencychart in accordance with the described embodiments.

FIG. 15 presents a vectorized loop from program code with mutualdependences in accordance with the described embodiments.

FIG. 16 presents a vectorized loop from program code with mutualdependences in accordance with the described embodiments.

FIG. 17 presents a vectorized loop from program code with summation inaccordance with the described embodiments.

FIGS. 18A-18B present a vectorized loop from program code with summationin accordance with the described embodiments.

FIGS. 19A-19B present a vectorized loop from program code that has beenvectorized both horizontally and vertically in accordance with thedescribed embodiments.

FIG. 20 presents a flowchart illustrating a process for executingprogram code in accordance with the described embodiments.

FIG. 21A-21B presents a flowchart illustrating a process for executingprogram code in accordance with the described embodiments.

FIG. 22A-22B presents a flowchart illustrating a process for executingprogram code in accordance with the described embodiments.

FIG. 23A-23B presents a flowchart illustrating a process for executingprogram code in accordance with the described embodiments.

FIG. 24A-24B presents a flowchart illustrating a process for executingprogram code in accordance with the described embodiments.

FIG. 25A-25B presents a flowchart illustrating a process for executingprogram code in accordance with the described embodiments.

FIG. 26A-26B presents a flowchart illustrating a process for executingprogram code in accordance with the described embodiments.

In the figures, like reference numerals refer to the same figureelements throughout the drawings. Moreover, multiple instances of thesame element are designated by a common prefix separated from aninstance number by a dash.

DETAILED DESCRIPTION

The following description is presented to enable any person skilled inthe art to make and use the disclosed embodiments, and is provided inthe context of a particular application and its requirements. Variousmodifications to the disclosed embodiments will be readily apparent tothose skilled in the art, and the general principles defined herein maybe applied to other embodiments and applications without departing fromthe spirit and scope of the present embodiments. Thus, the system is notlimited to the embodiments shown, but is to be accorded the widest scopeconsistent with the principles and features disclosed herein.

The data structures and code herein described are typically stored on acomputer-readable storage device, which may be any device or medium thatcan store code and/or data for use by a computer system (e.g., computersystem 100). The computer-readable storage device includes, but is notlimited to, volatile memory, non-volatile memory, magnetic and opticalstorage devices such as disk drives, magnetic tape, CDs (compact discs),DVDs (digital versatile discs or digital video discs), or other mediacapable of storing computer-readable media now known or later developed.Note that non-statutory media such as transitory signals are notincluded in the computer-readable storage devices in these embodiments.

The methods and processes described in the detailed description sectioncan be embodied as code and/or data, which can be stored in acomputer-readable storage device as described above. When a computersystem reads and executes the code and/or data stored on thecomputer-readable storage device, the computer system performs themethods and processes embodied as data structures and code and storedwithin the computer-readable storage medium.

Furthermore, the methods and processes described below can be includedin hardware modules. For example, the hardware modules can include, butare not limited to, application-specific integrated circuit (ASIC)chips, field-programmable gate arrays (FPGAs), and otherprogrammable-logic devices now known or later developed. When thehardware modules are activated, the hardware modules perform the methodsand processes included within the hardware modules.

Terminology

Throughout the description, we use the following terminology. Theseterms may be generally known in the art, but are described below toclarify the subsequent descriptions.

The term “cycle” as used in this description refers to a quantum of timein which an operation happens. Although a cycle can be exactly one clockcycle, in some embodiments one “cycle” includes two or more clockcycles. Moreover, although one operation may be performed during a givencycle, that operation may include any number of sub-operations. Forexample, when referring to a vector execution unit performing anoperation “in a cycle,” this means that sufficient time has passed toenable the execution unit to have completed the described operation.

The term “vector-length agnostic” as used in this description indicatesthat an operation (i.e., instruction, etc.) can be executed usingvectors of any length, up to the limitations imposed by the supportinghardware. For example, assuming that the vector execution hardwaresupports 256-bit vectors that can include eight separate four-bytewords, a vector-length agnostic operation can operate on any number ofthe eight words in the vector.

The term “active element,” as used in this description to refer to oneor more elements of a vector, indicates elements that are operated onduring a given operation. Generally, the described embodiments enable avector execution unit to selectively perform parallel operations on oneor more available elements in a given vector in parallel. For example,an operation can be performed on only the first two of eight elements ofthe vector in parallel. In this case, the first two elements are “activeelements,” while the remaining six elements are “inactive elements.” Inthe described embodiments, one or more other vectors can be used todetermine which elements in a given operand vector are active (i.e., areto be operated on). For example, a “predicate vector” (described indetail below) can include “active” elements that are used to determinewhich elements in the operand vector to perform operations on. In someembodiments, non-zero elements are active elements.

The terms “true indicator” and “false indicator” are used in thisdescription to refer to data values (e.g., a data value contained in anelement in a vector). Generally, in computer systems true and false areoften represented by 1 and 0, respectively. In practice, a givenembodiment could use any value to represent true and false, such as thenumber 55, or the letter “T.”

Computer System

FIG. 1 presents a block diagram of a computer system 100 in accordancewith the described embodiments. Computer system 100 includes processor102, L2 cache 106, memory 108, and mass-storage device 110. Processor102 includes L1 cache 104.

Processor 102 can be a general-purpose processor that performscomputational operations. For example, processor 102 can be a centralprocessing unit (CPU) such as a microprocessor, a controller, anapplication-specific integrated circuit (ASIC), or a field-programmablegate array (FPGA). In the described embodiments, processor 102 has oneor more mechanisms for vector processing (i.e., vector execution units).Processor 102's vector execution unit is described in detail below.

Mass-storage device 110, memory 108, L2 cache 106, and L1 cache 104 arecomputer-readable storage devices that collectively form a memoryhierarchy that stores data and instructions for processor 102.Generally, mass-storage device 110 is a high-capacity, non-volatilememory, such as a disk drive or a large flash memory, with a largeaccess time, while L1 cache 104, L2 cache 106, and memory 108 aresmaller, faster semiconductor memories that store copies of frequentlyused data. Memory 108 is typically a dynamic random access memory (DRAM)structure that is larger than L1 cache 104 and L2 cache 106, whereas L1cache 104 and L2 cache 106 are typically comprised of smaller staticrandom access memories (SRAM). In some embodiments, L2 cache 106, memory108, and mass-storage device 110 are shared between one or moreprocessors in computer system 100. Such memory structures are well-knownin the art and are therefore not described in more detail.

In some embodiments, the devices in the memory hierarchy (i.e., L1 cache104, etc.) can access (i.e., read and/or write) multiple cache lines percycle. These embodiments enable more effective processing of memoryaccesses that occur based on a vector of pointers or array indices tonon-contiguous memory addresses.

Computer system 100 can be incorporated into many different types ofelectronic devices. For example, computer system 100 can be part of adesktop computer, a laptop computer, a server, a media player, anappliance, a cellular phone, a piece of testing equipment, a networkappliance, a personal digital assistant (PDA), a hybrid device (i.e., a“smart phone”) or another electronic device.

Although we use specific components to describe computer system 100, inalternative embodiments different components may be present in computersystem 100. For example, computer system 100 may not include some of thememory hierarchy (e.g., memory 108 and/or mass-storage device 110).Alternatively, computer system 100 may include video cards,video-capture devices, user-interface devices, network cards, opticaldrives, and/or other peripheral devices that are coupled to processor102 using a bus, a network, or another suitable communication channel.Computer system 100 may also include one or more additional processors,wherein the processors share some or all of L2 cache 106, memory 108,and mass-storage device 110.

Processor

FIG. 2 presents an expanded view of processor 102 in accordance with thedescribed embodiments. As is shown in FIG. 2, processor 102 includes L1cache 104, integer execution unit 202, floating-point execution unit206, and vector execution unit 204 (integer execution unit 202,floating-point execution unit 206, and vector execution unit 204 as agroup are interchangeably referred to as “the execution units”). Each ofthe execution units is used for performing computational operations,such as logical operations, mathematical operations, or bitwiseoperations for an associated type of operand. More specifically, integerexecution unit 202 is used for performing computational operations thatinvolve integer operands, floating-point execution unit 206 is used forperforming computational operations that involve floating-pointoperands, and vector execution unit 204 is used for performingcomputational operations that involve vector operands. Integer executionunits and floating-point execution units are generally known in the artand are not described in more detail.

In the described embodiments, vector execution unit 204 is asingle-instruction-multiple-data (SIMD) execution unit that performsoperations in parallel on some or all of the data elements that areincluded in vectors of operands. FIG. 3 presents an expanded view ofvector execution unit 204 in accordance with the described embodiments.As is shown in FIG. 3, vector execution unit 204 includes a vectorregister file 300 and an execution unit 302. Vector register file 300includes a set of vector registers that can hold operand vectors andresult vectors for execution unit 302. In some embodiments, there are 32vector registers in the vector register file, and each register includes128 bits. In alternative embodiments, there are different numbers ofvector registers and/or different numbers of bits per register.

Execution unit 302 retrieves operands from registers in vector registerfile 300 and executes vector instructions that cause execution unit 302to perform operations in parallel on some or all of the data elements inthe operand vector. For example, execution unit 302 can perform logicaloperations, mathematical operations, or bitwise operations on theelements in the vector. Execution unit 302 can perform one vectoroperation per cycle (although, as described above, the “cycle” mayinclude more than one cycle of a clock used to trigger, synchronize,and/or control execution unit 302's computational operations).

In the described embodiments, execution unit 302 supports vectors thathold N data elements (e.g., bytes, words, doublewords, etc.). In theseembodiments, execution unit 302 can perform operations on Nor fewer ofthe data elements in an operand vector in parallel. For example,assuming an embodiment where the vector is 256 bits in length, the dataelements being operated on are four-byte words, and the operation isadding a value to the data elements, these embodiments can add the valueto any number of the words in the vector.

In the described embodiments, execution unit 302 includes at least onecontrol signal that enables the dynamic limitation of the data elementsin an operand vector on which execution unit 302 operates. Specifically,depending on the state of the control signal, execution unit 302 may ormay not operate on all the data elements in the vector. For example,assuming an embodiment where the vector is 512 bits in length and thedata elements being operated on are four-byte words, the control signalcan be asserted to prevent operations from being performed on some orall of 16 data words in the operand vector. Note that “dynamically”limiting the data elements in the operand vector upon which operationsare performed can involve asserting the control signal separately foreach cycle at runtime.

In some embodiments, based on the values contained in a vector ofpredicates or one or more scalar predicates, execution unit 302 appliesvector operations to selected vector data elements only. In someembodiments, the remaining data elements in a result vector remainunaffected (which we call “predication”) or are forced to zero (which wecall “zeroing”). In some of these embodiments, the clocks for the dataelement processing subsystems (“lanes”) that are unused due topredication or zeroing in execution unit 302 can be gated, therebyreducing dynamic power consumption in execution unit 302.

The described embodiments are vector-length agnostic. Thus, a compileror programmer need not have explicit knowledge of the vector lengthsupported by the underlying hardware (e.g., vector execution unit 302).In these embodiments, a compiler generates or a programmer writesprogram code that need not rely on (or use) a specific vector length(some embodiments are forbidden from even specifying a specific vectorsize in program code). Thus, the compiled code in these embodiments(i.e., binary code) runs on other embodiments with differing vectorlengths, while potentially realizing performance gains from processorsthat support longer vectors. Consequently, as process technology allowslonger vectors, execution of legacy binary code simply speeds up withoutany effort by software developers.

In some embodiments, vector lengths need not be powers of two.Specifically, vectors of 3, 7, or another number of data elements can beused in the same way as vectors with power-of-two numbers of dataelements.

In the described embodiments, each data element in the vector cancontain an address that is used by execution unit 302 for performing aset of memory accesses in parallel. In these embodiments, if one or moreelements of the vector contain invalid memory addresses, invalidmemory-read operations can occur. In these embodiments, invalidmemory-read operations that would otherwise result in programtermination instead cause any elements with valid addresses to be readand elements with invalid elements to be flagged, allowing programexecution to continue in the face of speculative, and in hindsightillegal, read operations.

In some embodiments, processor 102 (and hence execution unit 302) isable to operate on and use vectors of pointers. In these embodiments,the number of data elements per vector is the same as the number ofpointers per vector, regardless of the size of the data type.Instructions that operate on memory may have variants that indicate thesize of the memory access, but elements in processor registers should bethe same as the pointer size. In these embodiments, processors thatsupport both 32-bit and 64-bit addressing modes may choose to allowtwice as many elements per vector in 32-bit mode, thereby achievinggreater throughput. This implies a distinct throughput advantage to32-bit addressing, assuming the same width data path.Implementation-specific techniques can be used to relax the requirement.For example, double-precision floating-point numbers can be supported in32-bit mode through register pairing or some other specializedmechanism.

Although we describe processor 102 as including a particular set ofexecution units, in alternative embodiments, processor 102 can includedifferent numbers or types of execution units. Moreover, although theembodiment shown in FIG. 2 is limited to a particular set of functionalblocks, in the described embodiments processor 102 can include otherfunctional blocks, such as an instruction fetch unit, an instructiondecode unit, a branch unit, a memory management unit, I/O interfaces,etc. coupled to the execution units. The additional functional blocksthat can be present in processor 102 are well-known in the art and arenot described in more detail.

Macroscalar Architecture

The described embodiments provide an instruction set and supportinghardware that allow compilers to generate program code for loops withouthaving to completely determine parallelism at compile-time, and withoutdiscarding useful static analysis information. Specifically, theseembodiments provide a set of instructions that do not mandateparallelism for loops but, instead, enable parallelism to be exploitedat runtime if dynamic conditions permit. These embodiments thus includeinstructions that enable code generated by the compiler to dynamicallyswitch between non-parallel (scalar) and parallel (vector) execution forloop iterations depending on conditions at runtime by switching theamount of parallelism used.

As described, these embodiments provide instructions that enable anundetermined amount of vector parallelism for loop iterations but do notrequire that the parallelism be used at runtime. More specifically,these embodiments include a set of vector-length agnostic instructionswhose effective vector length can vary depending on runtime conditions.Thus, if runtime dependencies demand non-parallel execution of the code,then execution occurs with an effective vector length of one element.Likewise, if runtime conditions permit parallel execution, the same codeexecutes in a vector-parallel manner to whatever degree is allowed byruntime dependencies (and the vector length of the underlying hardware).For example, if two out of eight elements of the vector can safelyexecute in parallel, the described embodiments execute the two elementsin parallel. In these embodiments, expressing program code in avector-length agnostic format enables a broad range of vectorizationopportunities that are not present in existing systems.

In the described embodiments, during compilation, a compiler firstanalyzes the loop structure of a given loop in program code and performsstatic dependency analysis. The compiler then generates program codethat retains static analysis information and instructs processor 102 howto resolve runtime dependencies and process the program code with themaximum amount of parallelism possible. More specifically, the compilerprovides vector instructions for performing corresponding sets of loopiterations in parallel, and provides vector-control instructions fordynamically limiting the execution of the vector instructions to preventdata dependencies between the iterations of the loop from causing anerror. This approach defers the determination of parallelism to runtime,where the information on runtime dependencies is available, therebyallowing the software and processor to adapt parallelism to dynamicallychanging conditions.

FIG. 4 presents an example of the parallelization of a loop in programcode in accordance with the described embodiments. On the left side ofFIG. 4 is shown an execution pattern for four iterations of a loop thathave not been parallelized, where each loop includes instructions A-G.On the right side of FIG. 4 is shown a parallelized version of the loopin accordance with the described embodiments. In this example, we assumethat each instruction within an iteration depends on at least oneinstruction before it, so that there is a static dependency chainbetween the instructions of a given iteration. Hence, the instructionswithin a given iteration cannot be parallelized (i.e., instructions A-Gwithin a given iteration are always serially executed with respect tothe other instructions in the iteration). Note that in alternativeembodiments the instructions within a given iteration can beparallelizable.

As shown by the arrows between the iterations of the loop in FIG. 4,there is a possibility of a runtime data dependency between instructionE in a given iteration and instruction D of the subsequent iteration.However, during compilation, the compiler can only determine that thepossibility of data dependency exists between these instructions. Thecompiler cannot tell in which iterations dependencies actuallymaterialize, because this information is only available at runtime. Inthis example, a data dependency that actually materializes at runtime isshown by the solid arrows in FIG. 4, while a data dependency thatdoesn't materialize at runtime is shown using a dashed arrow. Thus, asshown in FIG. 4, a runtime data dependency actually occurs between thefirst/second and third/fourth iterations.

Because no data dependency exists between the second and thirditerations, the second and third iterations can safely be processed inparallel. Furthermore, instructions A-C and F-G of a given iterationhave dependencies only within an iteration and, therefore, instruction Aof a given iteration is able to execute in parallel with instruction Aof any other iteration, instruction B can also execute in parallel withinstruction B of any other iteration, and so forth.

The right side of FIG. 4 shows a version of the loop that has beenparallelized in accordance with the observations above. The exampleshows how the iterations of such a loop can be executed to accommodateboth the static and runtime data dependencies, while achieving maximumparallelism. For instructions A-C, all four iterations can be executedin parallel. Then instructions D and E can be executed with the maximumamount of parallelism allowed by the runtime data dependencies.Specifically, because instruction D in the second iteration depends oninstruction E in the first iteration, instructions D and E in the firstiteration must be executed before instruction D for the second iterationcan be executed. However, because there is no data dependency betweenthe second and third iterations, instructions D and E for theseiterations can be executed in parallel. Finally, for instructions F-G,all four iterations can be executed in parallel.

Examples of the Embodiments

In the following section, we present a series of examples in describingthe embodiments. These examples introduce Macroscalar operations anddemonstrate their use in vectorizing loops in accordance with thedescribed embodiments. For ease of understanding, these examples arepresented using C++-formatted pseudocode.

The instructions and operations presented in this description areintended to aid in understanding the described embodiments. However, inalternative embodiments, an instruction or operation can be implementedin a different way, for example, using a microcode sequence of moreprimitive operations or using a different sequence of sub-operations.Note that further decomposition of instructions is avoided so thatinformation about the macro-operation and the corresponding usage modelis not obscured. Note also that additional definitions for eachinstruction may be provided in the “Macroscalar Instructions” section inthis description.

Notation

In describing the examples, we use the following formats for variables,which are vector quantities unless otherwise noted:

p5=a<b;

-   -   Elements of vector p5 are set to 0 or 1 depending on the result        of testing a<b. Note that vector p5 can be a “predicate vector,”        as described in detail below. Some instructions that generate        predicate vectors also set processor status flags to reflect the        resulting predicates. For example, the processor status flags        can include the FIRST, LAST, NONE, and/or ALL flags.        ˜p5; a=b+c;    -   Only elements in vector a designated by active (i.e., non-zero)        elements in the predicate vector p5 receive the result of b+c.        The remaining elements of a are unchanged. This operation is        called “predication,” and is denoted using the tilde (“˜”) sign        before the predicate vector.        !p5; a=b+c;    -   Only elements in vector a designated by active (i.e., non-zero)        elements in the predicate vector p5 receive the result of b+c.        The remaining elements of a are set to zero. This operation is        called “zeroing,” and is denoted using the exclamation point        (“!”) sign before the predicate vector.

  if (FIRST( )) goto ...; Also LAST( ), ANY( ), ALL( ), CARRY( ), ABOVE(), or NONE( ), (where ANY( ) == !NONE ( ))

-   -   These instructions test the processor status flags and branch        accordingly.        x+=VECLEN;    -   VECLEN is a machine value that communicates the number of        elements per vector. The value is determined at runtime by the        processor executing the code, rather than being determined by        the assembler.

//Comment

-   -   In a similar way to many common programming languages, the        following examples use the double forward slash to indicate        comments. These comments can provide information regarding the        values contained in the indicated vector or explanation of        operations being performed in a corresponding example.

In these examples, other C++-formatted operators retain theirconventional meanings, but are applied across the vector on anelement-by-element basis. Where function calls are employed, they implya single instruction that places any value returned into a destinationregister. For simplicity in understanding, all vectors discussed in thispaper are vectors of integers, but alternative embodiments support otherdata formats.

Structural Loop-Carried Dependencies

Example 1 presents an example loop in program code that is“non-vectorizable” using conventional vector architectures. (Note thatin addition to being non-vectorizable, this loop is also notmulti-threadable on conventional multi-threading architectures due tothe fine-grain nature of the data dependencies.) For clarity, this loophas been distilled to the fundamental loop-carried dependencies thatmake the loop unvectorizable.

In this example, the variables r and s have loop-carried dependenciesthat prevent vectorization using conventional architectures. Notice,however, that the loop is vectorizable as long as the condition(A[x]<FACTOR) is known to be always true or always false. Theseassumptions change when the condition is allowed to vary duringexecution (the common case). For simplicity in this example, we presumethat no aliasing exists between A[ ] and B[ ]. Note that aliasing isaddressed in later sections.

r = 0; s = 0; for (x=0; x<KSIZE; ++x) {   if (A[x] < FACTOR)   {     r =A[x+s];   }   else   {     s = A[x+r];   }   B[x] = r + s; }

Example 1 Program Code Loop

In the described embodiments, the loop in Example 1 can be vectorized bypartitioning the vector into segments for which the conditional(A[x]<FACTOR) does not change. Exemplary processes for partitioning suchvectors, as well as exemplary instructions that enable the partitioning,are presented below. Note that for this example the describedpartitioning need only be applied to instructions within the conditionalclause. The first read of A[x] and the final operation B[x]=r+s canalways be executed in parallel across a full vector, except potentiallyon the final loop iteration.

We now present instructions and exemplary vectorized code in order toexplain the described embodiments. The following description isgenerally organized so that a number of instructions are described andthen one or more vectorized code samples that use the instructions arepresented. In some cases, a particular type of vectorization issue isexplored in a given example.

dest=VectorReadInt(base, offset)

VectorReadInt is an instruction for performing a memory read operation.A vector of offsets, offset, scaled by the data size (integer in thiscase) is added to a scalar base address, base, to form a vector ofmemory addresses which are then read into a destination vector. If theinstruction is predicated or zeroed, only addresses corresponding toactive elements are read. In the described embodiments, reads to invalidaddresses are allowed to fault, but such faults only result in programtermination if the first active address is invalid.

VectorWriteInt(base, offset, value)

VectorWriteInt is an instruction for performing a memory writeoperation. A vector of offsets, offset, scaled by the data size (integerin this case) is added to a scalar base address, base, to form a vectorof memory addresses. A vector of values, value, is written to thesememory addresses. If this instruction is predicated or zeroed, data iswritten only to active addresses. In the described embodiments, writesto illegal addresses always generate faults.

dest=VectorIndex(start, increment)

VectorIndex is an instruction for generating vectors of values thatmonotonically adjust by the increment from a scalar starting valuespecified by start. This instruction can be used for initializing loopindex variables when the index adjustment is constant. When predicationor zeroing is applied, the first active element receives the startingvalue, and the increment is only applied to subsequent active elements.For example:

x=VectorIndex(0,1); //x={0 1 2 3 4 5 6 7}

dest=PropagatePostT(dest, src, pred)

The PropagatePostT instruction propagates the value of active elementsin src, as determined by pred, to subsequent inactive elements of dest.Active elements, and any inactive elements that precede the first activeelement, remain unchanged in dest. The purpose of this instruction is totake a value that is conditionally calculated, and propagate theconditionally calculated value to subsequent loop iterations as occursin the equivalent scalar code. For example:

$\begin{matrix}{{Entry}\text{:}} & {{dest} = \begin{Bmatrix}8 & 9 & A & B & C & D & E & F\end{Bmatrix}} \\\; & {{src} = \begin{Bmatrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\end{Bmatrix}} \\\; & {{pred} = \begin{Bmatrix}0 & 0 & 1 & 1 & 0 & 0 & 1 & 0\end{Bmatrix}} \\{{Exit}\text{:}} & {{dest} = \begin{Bmatrix}8 & 9 & A & B & 4 & 4 & E & 7\end{Bmatrix}}\end{matrix}$  dest = PropagatePriorF(src, pred)

The PropagatePriorF instruction propagates the value of the inactiveelements of src, as determined by pred, into subsequent active elementsin dest. Inactive elements are copied from src to dest. If the firstelement of the predicate is active, then the last element of src ispropagated to that position. For example:

$\begin{matrix}{{Entry}\text{:}} & {{src} = \begin{Bmatrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\end{Bmatrix}} \\\; & {{pred} = \begin{Bmatrix}1 & 0 & 1 & 1 & 0 & 0 & 1 & 0\end{Bmatrix}} \\{{Exit}\text{:}} & {{dest} = \begin{Bmatrix}8 & 2 & 2 & 2 & 5 & 6 & 6 & 8\end{Bmatrix}}\end{matrix}$ dest = ConditionalStop(pred, deps)

The conditionalStop instruction evaluates a vector of predicates, pred,and identifies transitions between adjacent predicate elements thatimply data dependencies as specified by deps. The scalar value deps canbe thought of as an array of four bits, each of which designates apossible transition between true/false elements in pred, as processedfrom left to right. These bits convey the presence of the indicateddependency if set, and guarantee the absence of the dependency if notset. They are:

-   -   kTF—Implies a loop-carried dependency from an iteration for        which the predicate is true, to the subsequent iteration for        which the value of the predicate is false.    -   kFF—Implies a loop-carried dependency from an iteration for        which the predicate is false, to the subsequent iteration for        which the value of the predicate is false.    -   kFT—Implies a loop-carried dependency from an iteration for        which the predicate is false, to the subsequent iteration for        which the value of the predicate is true.    -   kTT—Implies a loop-carried dependency from an iteration for        which the predicate is true, to the subsequent iteration for        which the value of the predicate is true.

The element position corresponding to the iteration that generates thedata that is depended upon is stored in the destination vector at theelement position corresponding to the iteration that depends on thedata. If no data dependency exists, a value of 0 is stored in thedestination vector at that element. The resulting dependency indexvector, or DIV, contains a vector of element-position indices thatrepresent dependencies. For the reasons described below, the firstelement of the vector is element number 1 (rather than 0).

As an example, consider the dependencies in the loop of Example 1. Inthis loop, transitions between true and false iterations of theconditional clause represent a loop-carried dependency that requires abreak in parallelism. This can be handled using the followinginstructions:

  p1 = (t < FACTOR); // p1 = { 0 0 0 0 1 1 0 0 } p2 =ConditionalStop(p1, kTF|kFT); // p2 = { 0 0 0 0 4 0 6 0 }

Because the 4th iteration generates the required data, and the 5thiteration depends on it, a 4 is stored in position 5 of the outputvector p2 (interchangeably called the “dependency index vector” or“DIV”). The same applies for the 7th iteration, which depends on datafrom the 6th iteration. Other elements of the DIV are set to 0 toindicate the absence of dependencies. (Note that in this example thefirst element of the vector is element number 1.)

dest=GeneratePredicates(pred, DIV)

GeneratePredicates takes the dependency index vector, DIV, and generatespredicates corresponding to the next group of elements that may safelybe processed in parallel, given the previous group that was processed,indicated by pred. If no elements of pred are active, predicates aregenerated for the first group of elements that may safely be processedin parallel. If pred indicates that the final elements of the vectorhave been processed, then the instruction generates a result vector ofinactive predicates indicating that no elements should be processed andthe ZF flag is set. The CF flag is set to indicate that the last elementof the results is active. Using the values in the first example,GeneratePredicates operates as follows:

Entry Conditions: // i2 = { 0 0 0 0 4 0 6 0 } p2 = 0; // p2 = { 0 0 0 00 0 0 0 } Loop2:    p2 = GeneratePredicates(p2,i2); // p2′ = { 1 1 1   1 0 0 0 0 } CF = 0, ZF = 0    if(!CARRY( )) goto Loop2// p2″ = { 0 00 0 1 1 0    0 } CF = 0, ZF = 0                // p2′″ = { 0 0 0 0    00 1 1 } CF = 1, ZF = 0

From an initialized predicate p2 of all zeros, GeneratePredicatesgenerates new instances of p2 that partition subsequent vectorcalculations into three sub-vectors (i.e., p′, p″, and p′″). Thisenables the hardware to process the vector in groups that avoidviolating the data dependencies of the loop.

FIG. 5 presents two tables illustrating operation using vectorized codein accordance with the described embodiments. The top of FIG. 5 presentsa table illustrating a sequence of states through which scalar executionof the loop in Example 1 might progress using a randomized 50/50distribution of the direction of the conditional expression. The bottomof FIG. 5 presents a table illustrating a progression of execution forMacroscalar vectorized program code in accordance with the describedembodiments. In FIG. 5, the values read from A[ ] are shown usingleftward-slanting hash marks, while the values written to B[ ] are shownusing rightward-slanting hash marks, and values for “r” or “s”(depending on which is changed in a given iteration) are shown using ashaded background. Observe that “r” never changes while “s” is changing,and vice-versa.

Nothing prevents all values from being read from A[ ] in parallel orwritten to B[ ] in parallel, because neither set of values participatesin the loop-carried dependency chain. However, for the calculation of rand s, elements can be processed in parallel only while the value of theconditional expression remains the same (i.e., runs of true or false).This pattern for the execution of the program code for this loop isshown in the lower portion of FIG. 5. Note that the example uses vectorseight elements in length. When processing the first vector instruction,the first iteration is performed alone (i.e., execution unit 302processes only the first vector element), whereas iterations 1-5 areprocessed in parallel by execution unit 302, and then iterations 6-7 areprocessed in parallel by execution unit 302.

FIG. 6 presents exemplary vectorized program code in accordance with thedescribed embodiments. In FIG. 6, the top portion contains the originalsource code, while the bottom portion contains vectorized coderepresenting the operations that may be performed by the describedembodiments. In the vectorized code, Loop1 is the loop from the sourcecode, while Loop2 is the vector-partitioning loop that processes thesub-vector partitions.

In the example, array A[ ] is read and compared in full-length vectors(i.e., for a vector of N elements, N positions of array A[ ] are read atonce). Vector i2 is the DIV that controls partitioning of the vector.Partitioning is determined by monitoring the predicate p1 fortransitions between false and true, which indicate loop-carrieddependencies that should be observed. Predicate vector p2 determineswhich elements are to be acted upon at any time. In this particularloop, p1 has the same value in all elements of any sub-vector partition;therefore, only the first element of the partition needs to be checkedto determine which variable to update.

After variable s is updated, the PropagatePostT instruction propagatesthe final value in the active partition to subsequent elements in thevector. At the top of the loop, the PropagatePriorF instruction copiesthe last value of s from the final vector position across all elementsof the vector in preparation for the next pass. Note that variable r ispropagated using a different method, illustrating the efficiencies ofusing the PropagatePriorF instruction in certain cases.

Software Speculation

In the previous example, the vector partitions prior to the beginning ofthe vector-partitioning loop could be determined because thecontrol-flow decision was independent of the loop-carried dependencies.This is not always the case. Consider the following two loops:

j = 0; for (x=0; x<KSIZE; ++x) {   if (A[x] < FACTOR)   {     j =A[x+j];   }   B[x] = j; }

Example 2A Program Code Loop

j = 0; for (x=0; x<KSIZE; ++x) {  if (A[x+j] < FACTOR)  {   j = A[x];  } B[x] = j; }

Example 2B Program Code Loop

In Example 2A, the control-flow decision is independent of theloop-carried dependency chain, while in Example 2B the control flowdecision is part of the loop-carried dependency chain. In someembodiments, the loop in Example 2B leads the described embodiments tospeculate that the value of j remains unchanged and compensate later ifthis prediction proves incorrect. In these embodiments, the speculationon the value of j does not significantly change the vectorization of theloop.

In some embodiments, the compiler can be configured to always predict nodata dependencies between the iterations of the loop. In theseembodiments, in the case that runtime data dependencies exist, the groupof active elements processed in parallel can be reduced to represent thegroup of elements that may safely be processed in parallel at that time.In these embodiments, there is little penalty for mispredicting moreparallelism than actually exists because no parallelism is actually lost(i.e., if necessary, the iterations can be processed one element at atime, in a non-parallel way). In these embodiments, the actual amount ofparallelism is simply recognized at a later stage.

dest=VectorReadIntFF(base, offset)

VectorReadIntFF is a first-faulting variant of VectorReadInt. Thisinstruction does not generate a fault if at least the first activeelement is a valid address. Unmapped or illegal addresses after thefirst active element are nothing in the fault-status register. If thefirst active element of the address is unmapped, this instruction faultsto allw a virtual memory (VM) system in computer system 100 (not shown)to populate the page ensuring forward progress. Fault handling isdescribed in more detail below.

dest=Remaining(pred)

The Remaining instruction evaluates a vector of predicates, pred, andcalculates the remaining elements in the vector. This corresponds to theset of inactive predicates following the last active predicate. If thereare no active elements in pred, a vector of all active predicates isreturned. Likewise, if pred is a vector of all active predicates, avector of inactive predicates is returned. For example:

$\begin{matrix}{{Entry}\text{:}} & {{pred} = \begin{Bmatrix}0 & 0 & 1 & 0 & 1 & 0 & 0 & 0\end{Bmatrix}} \\{{Exit}\text{:}} & {{dest} = \begin{Bmatrix}0 & 0 & 0 & 0 & 0 & 1 & 1 & 1\end{Bmatrix}}\end{matrix}$

FIGS. 7A-7B present exemplary vectorized code in accordance with thedescribed embodiments. The code sample shown in FIG. 7A is a vectorizedversion of the code in Example 2A (as presented above). The code sampleshown in FIG. 7B is a vectorized version of the code in Example 2B. Inthe vectorized code in FIG. 7B, the read of A[ ] and subsequentcomparison have been moved inside the vector-partitioning loop. Thus,these operations presume (speculate) that the value of j does notchange. Only after using j is it possible to determine where j maychange value. After j is updated, the remaining vector elements arere-computed as necessary to iterate through the entire vector. The useof the Remaining instruction in the speculative code sample allows theprogram to determine which elements remain to be processed in thevector-partitioning loop before the program can determine the sub-groupof these elements that are actually safe to process (i.e., that don'thave unresolved data dependencies).

The described embodiments include fault-tolerant read support. Thus, inthese embodiments, processor 102 can speculatively read data from memoryusing addresses from invalid elements of a vector instruction (e.g,VectorReadFF) in an attempt to load values that are to be later used incalculations. However, upon discovering that an invalid read hasoccurred, these values are ultimately discarded and, therefore, notgermane to correct program behavior. Because such reads may referencenon-existent or protected memory, these embodiments are configured tocontinue normal execution in the presence of invalid but irrelevant datamistakenly read from memory. (Note that in embodiments that supportvirtual memory, this has the additional benefit of not paging until theneed to do so is certain.)

In the loop shown in FIG. 7A-7B, there exists a loop-carried dependencybetween iterations where the condition is true, and subsequentiterations, regardless of the predicate value for the later iterations.This is reflected in the parameters of the ConditionalStop instruction.

The sample code in FIGS. 7A-7B highlights the differences betweennon-speculative and speculative vector partitioning. In Example 2A,memory is read and the predicate is calculated prior to theConditionalStop. The partitioning loop begins after the ConditionalStopinstruction. In Example 2B, the ConditionalStop instruction is executedinside the partitioning loop, and serves to recognize the dependenciesthat render earlier operations invalid. In both cases, theGeneratePredicates instruction calculates the predicates that controlwhich elements are used for the remainder of the partitioning loop.

Memory-Based Loop-Carried Dependencies

The examples presented thus far presume the compiler was able toestablish that no address aliasing existed at the time of compilation.Such determinations are often very difficult or impossible to make. Thenext example shows how loop-carried dependencies occurring throughmemory (which may include aliasing) are dealt with in the describedembodiments (i.e., in the Macroscalar architecture). Consider thefollowing loop:

for (x=0; x<KSIZE; ++x) {  r = C[x];  s = D[x];  A[x] = A[r] + A[s]; }

Example 3 Program Code Loop

In Example 3, the compiler cannot determine at compile-time whether A[x]aliases with A[r] or A[s]. However, in the described embodiments, thecompiler inserts instructions that cause the hardware to check formemory hazards at runtime and partitions the vector accordingly atruntime to ensure correct program behavior.

dest=CheckHazardP(first, second, pred)

CheckHazardP examines two vectors of memory addresses (or indices)corresponding to two memory operations for potential data dependenciesthrough memory. The vector first holds addresses for the first memoryoperation, and vector second holds addresses for the second operation.The predicate pred indicates which elements of second are to be operatedupon. As scalar loop iterations proceed forward in time, vector elementsrepresenting sequential iterations appear left to right within vectors.CheckHazardP evaluates hazards in this context. The instructioncalculates a DIV representing memory hazards between the correspondingpair of first and second memory operations. The instruction correctlyevaluates write-after-read, read-after-write, and write-after-writememory hazards.

As with the ConditionalStop instruction, the element positioncorresponding to the iteration that generates the data that is dependedupon is stored in the destination vector at the element positioncorresponding to the iteration that is dependent upon the data. If nodata dependency exists, a zero is stored in the destination vector atthe element position corresponding to the iteration that does not havethe dependency. For example:

$\begin{matrix}{{Entry}\text{:}} & {{first} = \begin{Bmatrix}2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\end{Bmatrix}} \\\; & {{second} = \begin{Bmatrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & 1\end{Bmatrix}} \\\; & {{pred} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\end{Bmatrix}} \\{{Exit}\text{:}} & {{dest} = \begin{Bmatrix}0 & 0 & 0 & 0 & 3 & 2 & 1 & 0\end{Bmatrix}}\end{matrix}$

Here, element 5 of the first vector (“first”) and element 3 of thesecond vector (“second”) both access array index 6. Therefore, a 3 isstored in position 5 of DIV. Likewise, element 6 of first and element 2of second both access array index position 7, causing a 2 to be storedin position 6 of DIV, and so forth. A zero is stored in DIV where nodata dependencies exist.

In some embodiments, the CheckHazardP instruction is configured toaccount for various sizes of data types. However, for clarity wedescribe the function of the instruction using only array index types.

The example above has three memory hazards. However, in the describedembodiments, only two partitions are needed to safely process theassociated memory operations. Close inspection reveals that handling thefirst hazard on element position 3 renders subsequent dependencies onlower or equally numbered element positions moot. For example:

  Entry Conditions: // DIV = { 0 0 0 0 3 2 1 0 } // p2 = { 0 0 0 0 0 0 00 } p2 = GeneratePredicates(p2,DIV); // p2 = { 1 1 1 1 0 0 0 0 } p2 =GeneratePredicates(p2,DIV); // p2 = { 0 0 0 0 1 1 1 1 }

The process used by the described embodiments to analyze a DIV todetermine where a vector should be broken is shown in pseudocode below.In some embodiments, processor 102 performs this calculation inparallel. For example:

List = <empty>; for (x=STARTPOS; x<VECLEN; ++x)  if (DIV[x] in List)  Break from loop;  else if (DIV[x] > 0)   Append <x> to List;

The vector may safely be processed in parallel over the interval[STARTPOS, x), where x is the position where DIV[x]>0, that is, fromSTARTPOS up to (but not including) position x, where STARTPOS refers tothe first vector element after the set of elements previously processed.If the set of previously processed elements is empty, then STARTPOSbegins at the first element.

In some embodiments, multiple DIVs may be generated in code usingConditionalStop and/or CheckHazardP instructions. The GeneratePredicatesinstruction, however, uses a single DIV to partition the vector. Thereare two methods for dealing with this situation: (1) partitioning loopscan be nested; or (2) the DIV's can be combined and used in a singlepartitioning loop. Either approach yields correct results, but theoptimal approach depends on the characteristics of the loop in question.More specifically, where multiple DIVs are expected not to havedependencies, such as when the compiler simply cannot determine aliasingon input parameters, these embodiments can combine multiple DIVs intoone, thus reducing the partitioning overhead. On the other hand, incases with an expectation of many realized memory hazards, theseembodiments can nest partitioning loops, thereby extracting the maximumparallelism possible (assuming the prospect of additional parallelismexists).

In some embodiments, DIVs can be combined using a VectorMax(A, B)instruction:

$\begin{matrix}{{{i\; 2} = {{CheckHazardP}\left( {a,c,{p\; 0}} \right)}};} & {{//{i\; 2}} = \begin{Bmatrix}0 & 0 & 2 & 0 & 2 & 4 & 0 & 0\end{Bmatrix}} \\{{{i\; 3} = {{CheckHazardP}\left( {b,c,{p\; 0}} \right)}};} & {{//{i\; 3}} = \begin{Bmatrix}0 & 0 & 1 & 3 & 3 & 0 & 0 & 0\end{Bmatrix}} \\{{{ix} = {{VectorMax}\left( {{i\; 2},{i\; 3}} \right)}};} & {{//{ix}} = \begin{Bmatrix}0 & 0 & 2 & 3 & 3 & 4 & 0 & 0\end{Bmatrix}}\end{matrix}$

Because the elements of a DIV should only contain numbers less than theposition of that element, which represent dependencies earlier in time,later dependencies only serve to further constrain the partitioning,which renders lower values redundant from the perspective of theGeneratePredicates instruction. Thus, taking the maximum of all DIVseffectively causes the GeneratePredicates instruction to return theintersection of the sets of elements that can safely be processed inparallel.

FIG. 8 presents a vectorized loop from program code with memory aliasingin accordance with the described embodiments. In this example noaliasing exists between C[ ] or D[ ] and A[ ], but operations on A[ ]may alias one another. If the compiler is unable to rule out aliasingwith C[ ] or D[ ], the compiler can generate additional hazard checks.Because there is no danger of aliasing in this case, the read operationson arrays C[ ] and D[ ] have been positioned outside thevector-partitioning loop, while operations on A[ ] remain within thepartitioning loop. If no aliasing actually exists within A[ ], thepartitions retain full vector size, and the partitioning loop simplyfalls through without iterating. However, for iterations where aliasingdoes occur, the partitioning loop partitions the vector to respect thedata dependencies, thereby ensuring correct operation.

In the example presented in FIG. 8, the hazard check is performed acrossthe entire vector of addresses. In the general case, however, it isoften necessary to check hazards between conditionally executed memoryoperations. The CheckHazardP instruction takes a predicate thatindicates which elements of the second memory operation are active. Ifnot all elements of the first operation are active, this CheckHazardPinstruction itself can be predicated with a zeroing predicatecorresponding to those elements of the first operand which are active.(Note that this yields correct results for cases where the first memoryoperation is predicated.)

FIG. 9 presents a vectorized loop from program code with memory aliasingin accordance with the described embodiments. As shown in FIG. 9, thetop portion is a loop with a memory hazard on array E[ ]. The codeconditionally reads and writes to unpredictable locations within thearray. The vectorized Macroscalar code for this loop is shown in thebottom portion in accordance with the described embodiments.

In the vectorized loop, p1 and p2 are predicates indicating whetherarray E[ ] is to be read or written, respectively. The CheckHazardPinstruction checks vectors of addresses (h and i) for memory hazards.The parameter p2 is passed to CheckHazardP as the predicate controllingthe second memory operation (the write). Thus, CheckHazardP identifiesthe memory hazard(s) between unconditional reads and conditional writespredicated on p2. The result of CheckHazardP is zero-predicated in p1.This places zeroes in the DIV (ix) for element positions that are not tobe read from E[ ]. Recall that a zero indicates no hazard. Thus, theresult, stored in ix, is a DIV that represents the hazards betweenconditional reads predicated on p1 and conditional writes predicated onp2. This is made possible because non-hazard conditions are representedwith a zero in the DIV.

Pseudo Loop-Carried Dependencies

The described embodiments can encounter pseudo loop-carrieddependencies. In these embodiments, not all references to valuescalculated during a previous iteration are actual loop-carrieddependencies. A common example is when a calculated value is compared toits value from the previous iteration. Such dependencies are merelyoverlapping dependencies and, hence, do not form a loop-carrieddependency chain. The following loop is used as an example:

j = 0; for (x=0; x<KSIZE; ++x) {  j = A[x] + A[x+1];  if (j != last)  {  B[x] = j;  }  last = j;  if (E[x] < RANGE)   continue;  if (C[x] <FACTOR)  {   D[x] = j;  } }

Example 4 Program Code Loop

dest=ShiftInRightP(in, vect, pred)

The ShiftInRightP instruction takes the scalar value in and places in inthe leftmost position of vector vect, shifting elements of vect to theright to make room. Shifted elements are propagated across elements thathave a zero-predicate in the parameter. The shifted vector is thenstored to the destination register. For example:

$\begin{matrix}{{Entry}\text{:}} & {{in} = 9} \\\; & {{vect} = \begin{Bmatrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\end{Bmatrix}} \\\; & {{pred} = \begin{Bmatrix}0 & 1 & 1 & 1 & 0 & 1 & 1 & 1\end{Bmatrix}} \\{{Exit}\text{:}} & {{dest} = \begin{Bmatrix}9 & 9 & 2 & 3 & 4 & 4 & 6 & 7\end{Bmatrix}}\end{matrix}$

dest=Continue(pred)

The Continue instruction evaluates the predicate pred, and returns thelogical negation of each active element. In the described embodiments,this instruction can be used to handle C-language “continue” statements.In the described embodiments, the Continue instruction performs asimilar operation to the logical “not” operation. For example:

$\begin{matrix}{{Entry}\text{:}} & {{pred} = \begin{Bmatrix}0 & 0 & 1 & 0 & 0 & 1 & 0 & 0\end{Bmatrix}} \\{{Exit}\text{:}} & {{dest} = \begin{Bmatrix}1 & 1 & 0 & 1 & 1 & 0 & 1 & 1\end{Bmatrix}}\end{matrix}$

FIG. 10 presents a vectorized loop from program code with pseudoloop-carried dependencies in accordance with the described embodiments.As shown in FIG. 10, the vector last represents a vector of last valuesof j. The vector last is calculated by shifting the vector j to theright one position. The last value of j from the previous pass is keptin the scalar q and is shifted into the earliest position of last.Likewise, the ultimate value of j from the current pass is copied intothe scalar q for the next pass by the “q=j” operation.

To process the “continue” statement in this loop, the predicate p1 iscalculated to constrain the elements for the remainder of the loop. Thisis predicated on p0 so that elements previously inactive remaininactive.

Conditional Updates

The described embodiments can encounter loop-carried dependencies thatoccur as the result of conditionally updating variables in loops. Forexample, incrementing a variable in every iteration is not considered aloop-carried dependency because the variable is a priori computable by acompiler. However, if the increment occurs conditionally, then aloop-carried dependency can be created.

y = 0; for (x=0; x<KSIZE; ++x) {  B[x] = A[y];  if (A[x] < FACTOR1)  ++y;  if (y >= FACTOR2)   y = 0;  C[x] = A[y]; }

Example 5 Program Code Loop

Note that in Example 5, the variable y is used before being updated.This is a common occurrence, but this case presents another obstacle tovectorization: a vector y must be calculated to determine the values ofy before y was calculated. This loop also uses y after y is updated.

This example conditionally updates the variable y either by incrementingy or resetting y to zero. Although y is a loop-carried dependencybecause y is conditionally updated, note that there are two situationswhere its value is predictable, thereby allowing parallelism: iterationswhere y is incremented but not reset, and iterations where y remainsunchanged.

dest=IncrPropagate1(value, pred)

This instruction returns a vector corresponding to the values of avariable before the variable is incremented. Only the first activeelement of value is referenced in this calculation. The parameter preddesignates the active elements. The post-increment value is propagatedacross inactive elements. For example:

$\begin{matrix}{{Entry}\text{:}} & {{value} = \begin{Bmatrix}2 & 4 & 2 & 4 & 2 & 4 & 2 & 4\end{Bmatrix}} \\\; & {{pred} = \begin{Bmatrix}0 & 1 & 1 & 1 & 0 & 0 & 1 & 1\end{Bmatrix}} \\{{Exit}\text{:}} & {{dest} = \begin{Bmatrix}2 & 4 & 5 & 6 & 7 & 7 & 7 & 8\end{Bmatrix}}\end{matrix}$

As shown, the first element of the vector remains unchanged because thefirst value is inactive. The second element remains unchanged becausethe second element's value before the second element is incremented isunchanged. The first active element in value (the second element in thisexample) serves as the basis for calculating the remaining activeelements.

dest=IncrPropagate2(value, pred)

This instruction returns a vector corresponding to the value of avariable after the variable is incremented. Only the first activeelement of value is referenced in this calculation. The parameter preddesignates which elements are active. The post-increment value ispropagated across inactive elements. For example:

$\begin{matrix}{{Entry}\text{:}} & {{value} = \left\{ \begin{matrix}2 & 4 & 2 & 4 & 2 & 4 & 2 & \left. 4 \right\}\end{matrix} \right.} \\\; & {{pred} = \left\{ \begin{matrix}0 & 1 & 1 & 1 & 0 & 0 & 1 & \left. 1 \right\}\end{matrix} \right.} \\{{Exit}\text{:}} & {{dest} = \left\{ \begin{matrix}2 & 5 & 6 & 7 & 7 & 7 & 8 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}$

dest=DecrPropagate1(value, pred)dest=DecrPropagate2(value, pred)

These instructions are the decrementing variants of IncrPropagate1 andIncrPropagate2, respectively. As described above, these instructionsreturn a vector corresponding to the value of a variable before andafter the variable is decremented, respectively. Only the first activeelement of value is referenced in this calculation. The parameter preddesignates which elements are active. The post-decrement value ispropagated across inactive elements.

FIG. 11 presents a vectorized loop from program code with conditionalupdates in accordance with the described embodiments. As shown in FIG.11, the comparison with FACTOR1 determines whether the variable y isincremented, and the comparison with FACTOR2 determines if y is to bereset. In the vectorized code, speculative partitioning is used,speculating that variable y is not to be reset. In some embodiments,speculative partitioning always speculates in the direction that allowsthe most parallelism.

In the outer loop, Loop1, vector p2 is initially cleared in preparationfor the GeneratePredicates instruction in Loop2. Because speculativepartitioning is being used, however, any remaining elements should bedetermined before GeneratePredicates executes. The Remaining instructiondetermines the number of elements remaining to be processed.GeneratePredicates may reduce this further based on the determination ofdependencies that were not available earlier.

Consolidation

It is common for variables calculated within loops to be used after theloop terminates. In the described embodiments, because the loops beingvectorized are initially scalar, some vectors may need to be re-cast asscalars for subsequent use. We call this process “consolidation.” Theseembodiments account for the case where a loop terminates prematurely andthe most recent value written to a register may not be its final value.In this case, the final scalar value of a variable may be from anearlier write that alters an element corresponding to a later iteration.For example, in Example 6 below the final scalar value for the variabler is 15. This is easily determinable because the calculations areunconditional.

for (x=0; x<10; ++x) {  r = x * 3;  if (x == 5)   break;  r = x * 2; }

Example 6 Program Code Loop

In the following loop, calculations of r are conditional, as are theconditions that can cause premature loop termination:

x = 0; for (; x<KSIZE; ++x) {  r = 23;  for (; x<KSIZE; ++x)  {   if(A[x] < FACTOR1)    r = A[x];   if (B[x] < FACTOR2)    break;   if (C[x]< FACTOR1)    r = C[x];   if (D[x] < FACTOR2)    break;   if (E[x] <FACTOR1)    r = E[x];   if (F[x] < FACTOR2)    break;  }  if (x < KSIZE) {   G[x] = r;  } }

Example 7 Program Code Loop

dest=PreBreak(pred)

The PreBreak instruction evaluates the predicate pred, which indicateswhich iteration (if any) prematurely exits the loop via a C-style“break” instruction. The instruction returns a predicate indicatingwhich loop iterations should be active before the break occurs. Forexample:

$\begin{matrix}{{Entry}\text{:}} & {{pred} = \left\{ \begin{matrix}0 & 0 & 0 & 1 & 0 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\{{Exit}\text{:}} & {{dest} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 0 & 0 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

dest=Break (pred)

The Break instruction evaluates the predicate pred, which indicateswhich iteration (if any) prematurely exits the loop via a C-style“break” instruction. The instruction returns a predicate indicatingwhich loop iterations should be active after the break occurs and statusflags reflecting this result. For example:

$\begin{matrix}{{Entry}\text{:}} & {{pred} = \left\{ \begin{matrix}0 & 0 & 0 & 1 & 0 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\{{Exit}\text{:}} & {{dest} = \left\{ \begin{matrix}1 & 1 & 1 & 0 & 0 & 0 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

dest=CopyPropagate(dest, src, pred)

The CopyPropagate instruction copies active elements of src, asdetermined by pred, into the destination dest. The copy operationeffectively progresses left to right. Any inactive elements prior to thefirst active element remain unchanged in dest. From this point forward,active elements are copied from src to dest. For inactive elements, thelast active element of src is propagated into dest. For example:

$\begin{matrix}{{Entry}\text{:}} & {{value} = \left\{ \begin{matrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & \left. 8 \right\}\end{matrix} \right.} \\\; & {{src} = \left\{ \begin{matrix}9 & A & B & C & D & E & F & \left. 0 \right\}\end{matrix} \right.} \\\; & {{pred} = \left\{ \begin{matrix}0 & 1 & 1 & 1 & 0 & 0 & 1 & \left. 1 \right\}\end{matrix} \right.} \\{{Exit}\text{:}} & {{dest} = \left\{ \begin{matrix}1 & A & B & C & C & C & F & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

FIGS. 12 and 13 present a vectorized loop from program code withconsolidation in accordance with the described embodiments. In thesefigures, FIG. 12 includes the original source code, while FIGS. 13A-13Binclude the vectorized code.

FIGS. 12 and 13A-13B illustrate a general case of consolidatingvariables in the presence of premature loop termination. For eachpossible early termination, both the Break and PreBreak results arerecorded, predicated on any prior termination condition. Before thearray G[ ] can be written, the correct value of r should be consolidatedfrom the various conditional reads that may have occurred. To accomplishthis, the shortest extent of the PreBreak conditions is used to mask theconditional read predicates, which are OR-ed together. This indicateswhich element of r is propagated. The CopyPropagate operation thenpropagates this value to the end of the vector. The scalar value of r isthen extracted using the PreBreak extent that was calculated earlier.

Interdependent Read-After-Write

Data dependencies in scalar code generally occur in a simple “to-from”form. When such code is vectorized, dependencies between vector elements(corresponding to instances of scalar variables in time) remain in theto-from form. However, because executing the vector instructions cancoalesce operations on variables that occur at different times in thescalar version of the code; paradoxical vector interdependencies can becreated. For example, consider the example loop and the dependency chartshown in FIG. 14. In the example loop, the scalar dependencies arestraightforward. The vectorization of this simple source code iscomplicated because in order to perform the write operation, the systemneeds a vector of t indices, but using the read operation to obtain avector of t indices potentially depends on the write occurring first.

This situation is unique to vectorized code. Scalar code does not sufferthis phenomenon because dependencies occur in different iterations atdifferent times. Another situation that can cause a mutual dependency iswhen a write occurs before a conditional break from a loop. If thetermination test depends on the write, a mutual dependency is createdbecause the existence of the write depends on the loop not terminatingprematurely.

Consider the two loops shown in Example 8A and 8B, below. Example 8Acontains a write to A[ ] between two reads of A[ ]. Because the writedepends on the variable k, and k is potentially dependent upon thewrite, a mutual dependence is created. Example 8B also has a mutualdependence, except that half of the mutual dependence is a control-flowdependency, while the other half is a data dependency. The write to B[ ]can only be allowed in iterations that should actually execute, but thebreak depends on the write to B[ ].

k = 99; for (x=0; x<KSIZE; ++x) {  j = A[D[x]];  A[C[x]] = j + k;  k =A[B[x]];  E[x] = k; }

Example 8A Program Code Loop

for (x=0; x<KSIZE; ++x) {  t = A[x];  B[x] = t;  if (B[t] < FACTOR)  break;  C[x] = B[t]; }

Example 8B Program Code Loop

dest=CheckHazardPx(first, second, pred)

CheckHazardPx evaluates two vectors of addresses/indices for potentialmemory hazards, where the operations may be interdependent. Thisinstruction is similar to the CheckHazardP instruction. UnlikeCheckHazardP, where each element of first is checked only againstlesser-ordered elements in second, CheckHazardPx also checksequal-numbered element positions in second. If these overlap then theelement position with the hazard is recorded in the next highest elementposition. For example:

$\begin{matrix}{{Entry}\text{:}} & {{first} = \begin{Bmatrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\end{Bmatrix}} \\\; & {{second} = \left\{ \begin{matrix}3 & 1 & 2 & 3 & 5 & 4 & 5 & \left. 6 \right\}\end{matrix} \right.} \\\; & {{pred} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 1 & 1 & \left. 1 \right\}\end{matrix} \right.} \\{{Exit}\text{:}} & {{dest} = \left\{ \begin{matrix}0 & 0 & 1 & 0 & 0 & 5 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

FIGS. 15-16 present two loops from program code with mutual dependencesalong with vectorized versions of these loops in accordance with thedescribed embodiments. In the example shown in FIG. 15, before writingto A[C[x]] it is necessary to perform the potentially dependent read ofA[B[x]] so that a vector of k can be calculated. This is accomplishedwith a vector-partitioning loop based on CheckHazardPx to break thevector where k actually depends on the write to A[ ]. To functioncorrectly where a single memory location is written and then read in thesame iteration, the original read is also required after the write. Inpractice this does not substantially affect performance because allvalues have been recently accessed and are in the cache. The dependencebetween A[D[x]] and A[B[x]] is handled with a CheckHazardP instruction.Because k is calculated in the iteration before k is used, theShiftInRightP instruction is used to move the data into the correctelement position.

In the example shown in FIG. 16, the loop may prematurely exit based ondata read from B[t], which occurs after the write to B[x]. The sametechnique is applied as in FIG. 15, but the data read from B[t] is usedto calculate whether a premature exit occurs and limit the writeaccordingly, thus ensuring that no writes occur for loop iterations thatwould not have executed in a sequential machine. Due to the possibilityof premature exit, when B[t] is re-read the terminating condition shouldbe re-calculated to ensure all loop exits are properly recognized.

Summation

A common operation is calculating the sum of a series of items. If therunning sum result is referenced within the loop, the result should becalculated each step of the way. Consider the following loop where aconditional running sum is stored to array B[ ].

v = v2 = 0; for (x=0; x<KSIZE; ++x) {  if (A[x] < FACTOR1)   v = A[x]; B[v] = v2;  if (A[x] > FACTOR2 && A[x] < FACTOR3)   continue;  v2 += v;}

Example 9 Program Code Loop

dest=RunningSum1P(base, addend, pred)

This instruction returns a vector corresponding to the value of avariable before a recursive add is performed on the variable. Only thefirst active element of vector base is used in this calculation. Thevector parameter addend holds the values that are added to base. Thevector parameter pred designates which elements are active. The post-addvalue is propagated across inactive elements. For example:

$\begin{matrix}{{Entry}\text{:}} & {{value} = \left\{ \begin{matrix}3 & 4 & 3 & 4 & 3 & 4 & 3 & \left. 4 \right\}\end{matrix} \right.} \\\; & {{addend} = \left\{ \begin{matrix}2 & 3 & 2 & 3 & 2 & 3 & 2 & \left. 3 \right\}\end{matrix} \right.} \\\; & {{pred} = \left\{ \begin{matrix}0 & 1 & 1 & 1 & 0 & 0 & 1 & \left. 1 \right\}\end{matrix} \right.} \\{{Exit}\text{:}} & {{dest} = \left\{ \begin{matrix}3 & 4 & 7 & 9 & 12 & 12 & 12 & \left. 14 \right\}\end{matrix} \right.}\end{matrix}$

As shown above, the first element in the vector remains unchangedbecause the first element of the vector is inactive. The second elementin the vector remains unchanged because the element retains its valuebefore the addend is added to the element. The first active element inbase (the second element in base) is the basis for the remainingcalculations.

dest=RunningSum2P(base, addend, pred)

This instruction returns a vector corresponding to the value of avariable after an addend gets recursively added to it. Only the firstactive element of base is used in this calculation. The parameter addendholds the values that are added to base. The parameter pred designateswhich elements are active. The post-add value is propagated acrossinactive elements. For example:

$\begin{matrix}{{Entry}\text{:}} & {{value} = \left\{ \begin{matrix}3 & 4 & 3 & 4 & 3 & 4 & 3 & \left. 4 \right\}\end{matrix} \right.} \\\; & {{addend} = \left\{ \begin{matrix}2 & 3 & 2 & 3 & 2 & 3 & 2 & \left. 3 \right\}\end{matrix} \right.} \\\; & {{pred} = \left\{ \begin{matrix}0 & 1 & 1 & 1 & 0 & 0 & 1 & \left. 1 \right\}\end{matrix} \right.} \\{{Exit}\text{:}} & {{dest} = \left\{ \begin{matrix}3 & 7 & 9 & 12 & 12 & 12 & 14 & \left. 17 \right\}\end{matrix} \right.}\end{matrix}$

Along with the RunningSum operations, the described embodiments cansupport other operations that “run” across the vector. In theseembodiments, there can be a number of instructions that encapsulatecommonly used operations across the vector in a vector-length agnosticmanner, thereby allowing the amount of parallelism to vary due toruntime dependencies. For example, some embodiments include a runningbitwise shift instruction for those loops that perform successive shiftsto process bits of a word. In these embodiments, the running-shiftinstruction takes the number of positions to shift as a vectorparameter, as well as a predicate to indicate when shifts occur and whenthey do not. In addition, some embodiments include running bitwise andlogical operations, such as AND/OR/XOR. Moreover, some embodimentsinclude a running-multiply, which addresses common functions such asexponentiation, factorial, and Taylor-series expansion.

FIG. 17 presents a vectorized loop from program code with summation inaccordance with the described embodiments. As shown in FIG. 17, whenvectorizing the source code, the write of B[ ] is relocated to thebottom of the loop body, which allows a vector of v2 sums to becalculated before they are written. In the original loop, the value ofv2 is used before the addition occurs, which first requires aRunningSum1P instruction to calculate a vector of v2 sums correspondingto the scalar values of v2 before the add occurs. After v2 is written,RunningSum2P is used to calculate a vector of v2 sums corresponding tothe scalar values of v2 after the addition is performed. This secondstep is necessary so the next pass can use the final value, although itis often the case that the final value is also needed later in the samepass.

A Complex Example

Example 10, below, presents a loop in program code that includes manyobstacles to conventional vectorization: pointer chasing, addressaliasing, irregular memory addressing, a data-serial function,unpredictable loop exit conditions, and loop-carried dependencies.Previous examples have illustrated how the described embodiments (i.e.,the Macroscalar architecture) address loop-carried dependencies,unpredictable loop termination, and irregular memory addressing. Example10 introduces two varieties of data-serial dependency chains. The firstis pointer-chasing, contained in the z=A[z] statement in the sourcecode. While pointer-chasing itself cannot be vectorized, many loopscontaining pointer chasing can, as is shown in this example. The seconddata-serial chain is an inner loop which performs an integer square-rootcalculation. In this inner loop, every iteration depends on the resultsof the prior iteration, and the loop exit depends on the final iterationand, therefore, cannot be predicted.

y = z = 0; for (x=0; x<LIMIT; ++x) {  z = A[z];  t = B[z];  tx = t;  ty= t / tx;  while (ty < tx)  {   tx = (tx + ty) / 2;   ty = t / tx;  } if (tx < FACTOR)  {   A[y++] = tx;  } }

Example 10 Program Code Loop

dest=VectorReadIntFF(base, offset)

VectorReadIntFF is a first-faulting variant of VectorReadInt. Thisinstruction does not generate a fault if an address is unmapped orotherwise illegal to access. Results corresponding to invalid addressesare noted in the fault-status register. If the first active element ofthe address is unmapped, this instruction sets the ZF flag to indicatethat no data was returned. Fault handling is described in more detailbelow.

FIGS. 18A-18B present a vectorized loop from program code with summationin accordance with the described embodiments. As shown in FIG. 18B, theinstruction VectorIndex(0, 1) is used to create a DIV i2 that partitionsthe vector into single-element sub-vectors, serializing the pointerchase. Because the pointer chase in this case is speculative, bothVectorReadIntFF and VectorReadIntNF are used to speculative chasepointers at the beginning of the loop to build a full vector of possiblepointers before proceeding with the rest of the loop. Note the use ofthe “above” conditional branch, which loops until the end of the vector,or until the first illegal read operation.

In all previous examples, vectorization was performed “horizontally,”that is, each element of the Macroscalar vectors represents acorresponding iteration of the loop. In this example there are twoloops: The outer “for” loop, and the inner “while” loop. The enclosing“for” loop is, as before, horizontally vectorized, but the inner “while”loop is vertically vectorized. In a vertically vectorized loop, thedescribed embodiments process the iterations of the loop sequentially intime, just like a scalar loop, but the data is a vector rather than ascalar loop. In vertically vectorized loops, the vector of data beingprocessed corresponds to multiple iterations of the enclosing loop. Inother words, a horizontal vector built in the enclosing “for” loop isiterated sequentially until the termination conditions of the “while”loop are met for all elements of the vector.

Horizontal and Vertical Vectorization

In the preceding examples of the described embodiments, verticalvectorization was applied because horizontal vectorization was notpossible due to serial dependence in the inner loop. However, verticalvectorization is an efficient vectorization technique in its own right,as demonstrated below.

for (x=0; x<LIMIT; ++x) {  t = A[x];  s = 0;  for (y=0; y<t; ++y)  {   s+= A[x+y];  }  B[x] = s; }

Example 11 Program Code Loop

The loop in Example 11 encloses a simple summation loop, which is bothhorizontally and vertically vectorized to illustrate the operationsperformed by the described embodiments. When the inner loop ishorizontally vectorized, a scalar region is generated around the innerloop that removes the inner loop from the surrounding vector context.

FIGS. 19A-19B present a vectorized loop from program code that has beenvectorized both horizontally and vertically in accordance with thedescribed embodiments. Note that the code from Example 11 above is thecode that has been vectorized in the examples in FIGS. 19A-19B.

Classifying Loops

Some embodiments classify loops according to the dependencies thataffect the vectorization of the loop. For example, in some embodiments,many loops, vectorizable or not, fall into one or more of theseclassifications:

-   -   Classically vectorizable loops: These loops contain no        loop-carried dependencies (LCD's) other than induction        variables.    -   Loops containing associative loop-carried dependencies (LCDs):        These loops contain LCDs over an associative operation. The LCD        may be executed conditionally or unconditionally. However, if        the LCD is conditionally executed, the condition must not form        part of the LCD chain. For example, these LCDs can be reduction        operations.    -   Loops containing conditional LCDs: These loops contain LCDs that        are executed conditionally, which may take the form of multiple        conditionally-interacting LCDs or conditionally executed        non-associative LCDs. For example, these LCDs can represent        control-flow hazards.    -   Loops containing memory hazards (potential LCDs): These loops        may contain actual address aliasing or addressing that the        compiler could not adequately disambiguate aliasing for        (may-alias).    -   Loops for which the degree of parallelism depends on LCD values:        These are loops for which the values of the LCDs result in other        run-time dependencies which affect the amount of available        parallelism in the loop. These loops are typically vectorized        using the above-described software speculation techniques.    -   Loops containing non-associative LCDs: This category includes        LCDs such as Newton-Raphson convergence and pointer-chasing.        These dependencies are generally vectorized using vertical        vectorization. Where vertical vectorization is not possible, the        loop may be partially vectorizable by serializing the        loop-carried dependency and vectorizing the remainder of the        loop.

Vectorizing Functions and Function Calls

In some embodiments, the compiler can replicate a function with aconventional scalar interface (i.e., a version of the function withscalar inputs and outputs) and create a secondary version with a vectorinterface (or can create a version with the vector interface alone).Such functions are typically vertically vectorized, for efficiency andsimplicity, although horizontal vectorization may also be applied. Inthese embodiments, function vectorization is most easily achieved incases where the function has no side effects on global, file-scopestatic, or function-local static storage. Functions using straight-linecode (without loops) can also be vertically vectorized, operating oneither full or partial vectors under the control of a predicate passedto the function in the compiler-generated vector interface.

If only “safe” functions are vectorized, the existence of the secondaryvariant guarantees that the function can safely and effectively becalled from within a vectorized loop. Thus, in the describedembodiments, Macroscalar vectorization techniques can be applied tovectorize commonly used functions such as sin( ), cos( ), tan( ), atan(), sqrt( ), etc. Doing so enables loops using these functions to callvector variants with vector interfaces, rather than incurring thebottleneck of a scalar interface.

While the scheme above works for file-local functions, library functionslike sin( ) have interfaces established through header files. Becausecompilers in the described embodiments generally do not make autonomousmodification of header files, in some embodiments, an annotationmechanism, such as compiler-generated XML files stored in standardizedlocations, provides additional compiler-generated source-level inputdescribing the secondary compiler-generated vector function interfaces.In these embodiments, the compiler attempts to open these annotationfiles implicitly upon inclusion of the appropriate header file. Forexample, upon inclusion of the header file <stdlib.h>, the compiler alsoattempts to load <stdlib.xml>. If the file did not exist, then thecompiler presumes that no vector interfaces existed.

In the described embodiments, the annotation mechanism also has thepotential to enable vectorization in other ways. For example, assume aloop calling two functions, one at the top of the loop body, foo( ) andthe other near the bottom, bar( ). In the absence of any deepinformation about these functions beyond their interfaces, the compileris forced to generate program code wherein the functions and the entirebody of code between them execute serially, one element at a time. Forexample, foo( ) might call srand( ), while bar( ) might call rand( ).Calling srand( ) multiple times before calling rand( ) is incorrect. If,on the other hand, the functions modify no non-local state, the compilervectorizes the code between the two function calls. The annotationscheme mentioned above can be extended to provide information about thefunctions and their descendants that enable the compiler to vectorizesuch code.

In the extended annotation scheme in the described embodiments,attributes of functions are propagated up through their callers tocommunicate key information to the compiler about all the functionscalled from a loop. Information as to whether the functions modifyfunction-scope static variables, pointed-to function parameters,file-scope static variables, or global variables is enormously valuable.For file-scope static variables, for example, the type of reference(read or write), the name of the variable, and the file where they arelocated might be communicated. For global variables, only the name andtype of reference is necessary. Knowledge that a function modifies noparameters or static state enables the compiler in the describedembodiments to forgo enforcement of atomicity on that function, therebyremoving that obstacle to vectorization.

The process in these embodiments is caller-guaranteed-correctness,assisted by trustable hints about the functions being called. Theabsence of a hint may cause the preclusion of an optimization, but isalways safe. In these embodiments, annotations begin at the bottom levelof the library, because non-annotated functions propagate uncertaintyupward, disabling many opportunities for vectorization.

Fault Handling

In the described embodiments, certain types of instructions can generateexceptions (or interrupts) in response to a fault condition resultingfrom the operation being performed. For example, memory operations thatcause a virtual-memory system in computer system 100 (not shown) tobring pages into memory or floating-point operations that invokesoftware fix-up handlers at run-time can cause computer system 100 togenerate exceptions. In these embodiments, instructions that cangenerate fault conditions can classified as “all-faulting instructions,”as “first-faulting instructions,” or as “non-faulting instructions.”All-faulting instructions generate an exception when the operation onany element position produces a fault. First-faulting instructionsgenerate exceptions only if a fault occurs in the first active element,i.e., the first element for which the predicate is enabled. Non-faultinginstructions suppress all exceptions that would otherwise have beengenerated from a fault in any element position.

In some embodiments processor 102 includes status and control registersor bits to that enable the management of faults and the resultingexceptions. For example, some embodiments include a Fault-statusRegister (FSR). The FSR is a bit-per-vector-element register that can beused to record that a faulting condition occurred at or before thecorresponding element position when the actual exception is suppressed.A bit being set in this register also indicates that any furtherexceptions generated by faults in the corresponding element are to besuppressed.

Some embodiments include a Fault Type Register (FTR). The FTR is aregister that indicates the type of fault that occurred at each elementposition when an actual exception is generated. Exceptions that havebeen masked by the FSR have no effect on this register.

Some embodiments include an Arithmetic Fault Mode (AFM) bit. This bitdetermines whether arithmetic instructions are to be processed inall-faulting or first-faulting mode.

Some embodiments include a Soft Terminate Mode (STM) bit. This bitdetermines how the OS should respond to normally fatal exceptions. Ifthe STM bit is set, the OS treats normally fatal exceptions in afirst-faulting manner; if the fatal exception comes from the firstactive position the program should be terminated. Otherwise, the OSshould set the appropriate FSR bits and resume execution.

Software Speculation

In the described embodiments, for software speculation, a compiler cangenerate code that presumes all vector elements can safely be processedin parallel. Then, at runtime, when the dynamic conditions thatdetermine actual parallelism are calculated, the vector size is reducedthrough predication to only the appropriate elements (i.e., the elementsthat can safely be processed in parallel). The reduction in vector sizeis due to a data dependency, which implies the remainder of thepresumptive element processing would likely not have occurred in thescalar program. Because of this, any faulting conditions in theseelements would also not have occurred in the scalar program. After thedata dependency is resolved, software-speculative code loops back andonce again presumes the remainder of the elements in the vector may allbe processed in parallel until determining that the remainder of theelements in the vector cannot be processed in parallel. (Note that inthis description, we use the term “fault” to mean an abnormal conditionthat would normally generate an exception in a scalar program. Inaddition, we use the term “exception” to mean an interruption in programexecution that is generated as a result of an unmasked fault.)

The above-described “first-faulting” and “non-faulting” instructionsprovide mechanisms to prevent faults from generating exceptions thatwould not be generated by the scalar program. Information about elementsthat have faulting conditions is used to restrict the width of thevector being processed, possibly to even fewer elements than dictated bydata dependencies. However the natural loop-back form ofsoftware-speculative code ensures that the faulting element eventuallybecomes the first active element, if the loop continues that far, thusguaranteeing that any legitimate exception occurs in the scalar codealso occurs in the described embodiments. These embodiments can alsoprevent the VM system from bringing in (i.e., retrieving from memory)pages that would not have been referenced by the correspondinginstruction(s) in the scalar program.

When an element in a first-faulting instruction encounters a faultingcondition, and that element is not the first active element, a bit isset in the Fault-status Register (FSR) corresponding to the faultingelement position. The Actual instruction can then consult this registerto determine which elements were actually processed without faults andreturn a predicate indicating those element positions.

Arithmetic operations can generate faults during speculative processing.By default, some code disables exceptions on floating-point arithmeticfaults. If a given program does not enable arithmetic faults, thedescribed embodiments may not take them into consideration (providehandling for such faults). Some programs, however, enable arithmeticfaults. For example, these programs can invoke floating-point fix-uphandlers for some faults. An example is programs that need to calculatesin(x)/x at x=0. Such programs would enable the divide-by-zero exceptionand fix-up the result of the calculation to be 1.0 when the exception istaken.

In some embodiments, a solution for the enabling of faults insoftware-speculative loops is to set the AFM bit to cause arithmeticinstructions to operate in a first-faulting mode of operation. Thisinsures only the necessary arithmetic exceptions are taken, but alsoreduces the effective parallelism whenever these exceptions are takenand causes the exceptions to be taken serially.

Some embodiments leave the AFM bit cleared, which causes arithmeticinstructions to operate in all-faulting mode. This method enables fullvector parallelism even in the presence of exceptions. An entire vectorof faults can be processed on one exception by having the exceptionhandler to consult the Fault Type register (FTR). This can reduce thenumber of exceptions taken, although it can also cause exceptions to betaken that would not have occurred in the scalar program. To ensure thatthe program is not incorrectly terminated by one of these extraneousexceptions, the Soft Terminate Mode (STM) bit should be set. Exceptionhandlers can then use this bit to determine how to handle potentiallyfatal exceptions. If the fatal exception was caused by the first activeelement, the program is terminated regardless of the state of the STMbit. However, if a fatal exception occurs in any subsequent position,the exception handler sets the corresponding bit in the FSR indicatingthat the exception was ignored. All bits in the FSR corresponding tosubsequent element positions should also be set. This effectively masksfurther exceptions from the faulting element and any subsequentelements.

When the data dependency causing software speculation is resolved inthese embodiments, the program may optionally employ the ActualFaultinstructions to ensure that fatal exceptions did not occur in elementpositions ahead of the dependency. These instructions ensure the programterminates if the scalar program would have terminated due to a fatalexception. If program termination is not desired, the ActualFaultinstruction can be omitted and the FSR cleared at the conclusion of theloop. Clearing the FSR at the conclusion of the loop eliminates theoverhead of checking for program termination inside the loop.

Loop Termination

In the described embodiments, unpredictable loop termination conditionscan result in the speculation that all elements are to be processeduntil it is determined that the loop actually terminates mid-vector. Inthese loops, the final vector being processed may read pages that thescalar program never read, potentially causing VM pages to be retrievedfrom disk unnecessarily, or possibly terminating the program based on aread from an illegal address. Consider the example below, where a fullvector is read from array A before the loop termination condition can becalculated, an operation that may read an illegal page that the scalarprogram would not have accessed—potentially leading to programtermination.

static double C[SIZE], B[SIZE], A[SIZE]; while (A[x] > 0) {  C[x] =B[x];  ++x; }

The described embodiments provide solutions for loops that haveunpredictable termination conditions. However, some embodiments includemechanisms for avoiding these problems. For example, linkers in theseembodiments can pad the end of the statically and dynamically allocatedstorage areas by an amount proportional to the hardware vector length ofthe machine. For example, padding by 8 bytes per vector element wouldallow the example above to negate the effects of reading past the end ofthe array. Padding by one additional 4K page would allow structures upto 512 bytes to be linearly accessed speculatively on a processor 102that used 8-element vectors.

In these embodiments, simple padding does not absolve all loops of faultchecking, as not all loops address arrays in linear fashion. However, insome embodiments, the loop above could be implemented usingfirst-faulting read instructions in the loop to ensure that the loopdoes not read into an illegal page. While this behavior is correct, thisbehavior requires additional overhead to manipulate the predicates andloop until the vector is complete or the loop naturally terminates.

In these embodiments, using soft-termination mode, this loop can employan all-faulting vector read that potentially reads an illegal page. Ifthis occurs, rather than terminating the program, the operating systemsets bits in the FSR in the position that faulted, as well as allsubsequent positions, before resuming program execution. This ensuresthat these elements do not take unnecessary multiple exceptions as theprogram progresses. After the loop termination condition is calculated,the program can check to ensure that none of the active elements wereresponsible for the exception using the ActualFault instructions.

In these embodiments, during normal program execution, anillegal-address exception typically only occurs at loop terminationtime. Because of this, a compiler in these embodiments may choose toinsert the Actual instruction into the loop itself, for debugging orrobustness. Alternatively, the compiler may choose the place the Actualinstruction at the end of the loop, thus virtually eliminating theoverhead of fault checking and taking the risk that could result in aproper program termination not being recognized.

Instruction Definitions

The following section contains exemplary instructions used in thedescribed embodiments (i.e., that are included in Macroscalararchitecture). The described instructions demonstrate the concepts usedin implementing the Macroscalar architecture and therefore do notcomprise a complete list of the possible instructions. A person of skillin the art will recognize that these concepts may be implemented usingdifferent arrangements or types of instructions without departing fromthe spirit of the described embodiments.

Unlike conventional single-instruction-multiple-data (SIMD) coding, insome embodiments, Macroscalar code can combine vector variables withscalar registers or immediate values. Thus, in these embodiments,Macroscalar instructions can directly reference scalar registers andimmediate values without making unnecessary vector copies of them. Notethat this can help avoid unnecessary vector-register pressure within aloop because more vector registers can be available instead of beingrequired for making vector copies of scalars or immediate values.

We describe these instructions using a signed-integer data type.However, in alternative embodiments, other data types or formats areused. Moreover, although Macroscalar instructions may take vector,scalar, or immediate arguments in practice, only vector arguments areshown here to avoid redundancy.

The descriptions of the instructions reference vector elements with azero-based numbering system (i.e., element “0” is the first element).However, certain instructions, such as those involved in the processingof DIVs, express dependencies using 1-based element numbering, eventhough they are actually implemented using 0-based element numbering.Care should be taken to avoid confusing the language the results areexpressed in from the language used to implement the instructions.

For the purposes of explanation, the vector data type is defined as aC++ class containing an array v[ ] of elements that comprise the vector.Within these descriptions, the variable VECLEN indicates the size of thevector. In some embodiments, VECLEN is constant.

In the following examples, predication is communicated to theinstructions via two variables. The vector gPred is the predicate vectorthat affects the instruction and/or the assignment of the result vector.A scalar variable, gPredFlag, indicates whether gPred functions in apredication or zeroing capacity. This variable is set to 0 when azeroing predicate is being applied, or is set to 1 otherwise.Additionally, some instructions may reference gPred to affect theoperation of the instruction apart from the final assignment. If aninstruction is not predicated, then all elements are considered active,and the vector gPred contains all true indicators.

Note that the format of the following instruction definitions is astatement of the instruction type followed by a description of theinstruction that can include example code as well as one or more usageexamples.

General-Purpose Vector Instructions

The instructions in this category perform the usual assortment ofC-style (i.e., as found in the C programming language) arithmeticoperations in vectors in an agnostic, predicated manner. The describedembodiments contain some operations not usually found in vectorinstructions sets, such as integer division and modulo operators.

Vector-Vector Assignment

During vector assignment, active vector elements, as determined byoptional predication, are copied into a destination vector. Inactiveelements either remain unmodified, or are forced to zero, depending onthe nature of the predication.

Predication and zeroing are applied at the assignment of the resultvector. Final assignment of the result vector is an implicit or explicitpart of every instruction that produces a result. Note that theassignment operator performs this function where predication or zeroingis not performed explicitly by the instruction.

const Vector Vector::operator = (const Vector &val) {   for (int x=0;x<VECLEN; ++x)     if (gPred.v[x])       v[x] = val.v[x];     else      v[x] &= −gPredFlag; // Not changed if       predicated, 0 ifzeroed   return(*this); }

Examples:

 ∼ p 0; a = b; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\\; & {b = \left\{ \begin{matrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & \left. 8 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 3 & 4 & 5 & 6 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = b};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\\; & {b = \left\{ \begin{matrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & \left. 8 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 3 & 4 & 5 & 6 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

Vector-Scalar Assignment

A scalar register or immediate value is copied into active elements ofthe destination vector, as determined by optional predication. Inactiveelements either remain unmodified, or are forced to zero, depending onthe nature of the predication.

const Vector & Vector::operator = (const _nt val) {   int x;   for (x=0;x<VECLEN; ++x)     if (gPred.v[x])       v[x] = val;     else       v[x]&= −gPredFlag; // Not changed if       predicated, 0 if zeroed  return(*this); }

Examples:

 ∼ p 0; a = b; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\\; & {b = 5} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 5 & 5 & 5 & 5 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = b};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\\; & {b = 5} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 5 & 5 & 5 & 5 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

Scalar-Vector Assignment (Vector Cast to Scalar)

This instruction casts a vector of values into a scalar register. Onlythe last active element, as determined by optional predication, iscopied to the scalar destination. If no elements are active, thisinstruction returns the first element of the vector.

Vector::operator int (void) const {   int x,rc;     for (x=VECLEN−1;x>=0; −−x) // Locate last     active element       if (gPred.v[x])        break;       rc = v[0]; // Use first element if there       areno active ones       if (x >= 0)         rc = v[x];   return(rc); }

Examples:

 ∼ p 0; a = int  (b); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = 2} \\\; & {b = \left\{ \begin{matrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & \left. 8 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = 6}\end{matrix}!}p\; 0};{a = {{int}\mspace{14mu} (b)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = 2} \\\; & {b = \left\{ \begin{matrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & \left. 8 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = 6}\end{matrix}$

GetFirst

The GetFirst instruction assigns the first active element of an inputvector, as determined using a predicate vector, to a scalar register.Generally, the first active element is the leftmost element of the inputvector for which a corresponding element of the predicate vector isactive (i.e., the first iteration of the loop represented by the inputvector for which a corresponding element of the predicate vector isactive). If no elements in the predicate vector are active, or if apredicate vector is assumed (as described below), the GetFirstinstruction sets the scalar register equal to the first/leftmost elementof the input vector.

int GetFirst(Vector &v) {   int x, rf;   rf = v[0]; // Use first elementif there are no   active elements   for (x=0; x<=VECLEN−1; x++) //Locate first   active element, if one exists     if (gPred.v[x])     {     rf = v[x];      break;     }    return(rf); }Examples (in these Examples, a is a Scalar Variable, e.g., an Int or aFloat):

 ∼ p 0; a = GetFirst  (b); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = 9} \\\; & {b = \left\{ \begin{matrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & \left. 8 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = 3}\end{matrix}!}p\; 0};{a = {{GetFirst}\mspace{14mu} (b)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = 9} \\\; & {b = \left\{ \begin{matrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & \left. 8 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = 3}\end{matrix}$

AssignLast

The AssignLast instruction assigns the last active element of an inputvector, as determined using a predicate vector, to a scalar register.Generally, the last active element is the rightmost element of the inputvector for which a corresponding element of the predicate vector isactive (i.e., the last iteration of the loop represented by the inputvector for which a corresponding element of the predicate vector isactive). If no elements in the predicate vector are active, or if apredicate vector is assumed (as described below), the AssignLastinstruction sets the scalar register equal to the last/rightmost elementof the input vector.

int AssignLast(Vector &v) {   int x, rf;   rf = v[VECLEN−1]; // Use lastelement if there   are no active elements   for (x=VECLEN−1; x>=0; x−−)// Locate last active   element, if one exists     if (gPred.v[x])     {      rf = v[x];       break;     }   return(rf); }Examples (in these Examples, a is a Scalar Variable, e.g., an Int or aFloat):

 ∼ p 0; a = AssignLast  (b); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = 9} \\\; & {b = \left\{ \begin{matrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & \left. 8 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = 6}\end{matrix}!}p\; 0};{a = {{AssignLast}\mspace{14mu} (b)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = 9} \\\; & {b = \left\{ \begin{matrix}1 & 2 & 3 & 4 & 5 & 6 & 7 & \left. 8 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = 6}\end{matrix}$

VectorNeg

This instruction mathematically negates active vector elements. Inactiveelements either remain unmodified, or are forced to zero, depending onthe nature of the predication. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction.

Vector VectorNeg(const Vector &ob) {   Vector result;   for (int x=0;x<VECLEN; ++x)     result.v[x] = −ob.v[x];   return(result); }

Examples

 ∼ p 0; a = −b; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\\; & {b = \left\{ \begin{matrix}{- 3} & {- 2} & {- 1} & 0 & 1 & 2 & 3 & \left. 4 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 1 & 0 & {- 1} & {- 2} & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {- b}};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\\; & {b = \left\{ \begin{matrix}{- 3} & {- 2} & {- 1} & 0 & 1 & 2 & 3 & \left. 4 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 1 & 0 & {- 1} & {- 2} & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorNot

This instruction logically negates active vector elements. Inactiveelements either remain unmodified, or are forced to zero, depending onthe nature of the predication. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction.

Vector VectorNot(const Vector &ob) {   Vector result;   for (int x=0;x<VECLEN; ++x)     result.v[x] = !ob.v[x];   return(result); }

Examples:

 ∼ p 0; a = VectorNot  (b); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\\; & {b = \left\{ \begin{matrix}0 & {- 2} & {- 1} & 0 & 1 & 2 & 3 & \left. 0 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 0 & 1 & 0 & 0 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {{VectorNot}\mspace{14mu} (b)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\\; & {b = \left\{ \begin{matrix}0 & {- 2} & {- 1} & 0 & 1 & 2 & 3 & \left. 0 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 0 & 1 & 0 & 0 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorInv

This instruction performs bitwise inversion active vector elements.Inactive elements either remain unmodified, or are forced to zero,depending on the nature of the predication. As shown below, in someembodiments, the instruction processes all elements equivalently;however, predication is performed by the assignment of the result, andshould be considered an integral part of this instruction.

Vector VectorInv(const Vector &ob) {   Vector result;   for (int x=0;x<VECLEN; ++x)     result.v[x] = ~ob.v[x];   return(result); }

Examples:

 ∼ p 0; a =  ∼ b; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\\; & {b = \left\{ \begin{matrix}{- 3} & {- 2} & {- 1} & 0 & 1 & 2 & 3 & \left. 4 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 0 & {- 1} & {- 2} & {- 3} & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {\sim b}};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\\; & {b = \left\{ \begin{matrix}{- 3} & {- 2} & {- 1} & 0 & 1 & 2 & 3 & \left. 4 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 1 & 0 & {- 1} & {- 2} & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorAdd

This instruction performs addition on active vector elements. Inactiveelements either remain unmodified, or are forced to zero, depending onthe nature of the predication. In this implementation, the instructiontakes the result vector as an input and performs predication explicitly.

Vector VectorAdd (const Vector &ob, const Vector &val, Vector *result) {  for (int x=0; x<VECLEN; ++x)     if (gPred.v[x])       result->v[x] =(ob.v[x] + val.v[x]);     else       result->v[x] &= −gPredFlag; // Not      changed if predicated, 0 if zeroed   return(*result); }

Examples:

 ∼ p 0; a = b + c; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 8 & 8 & 8 & 8 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {b + c}};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 8 & 8 & 8 & 8 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorSub

This instruction performs subtraction on active vector elements.Inactive elements either remain unmodified, or are forced to zero,depending on the nature of the predication. This implementation of theinstruction takes the result vector as an input and performs predicationexplicitly.

Vector VectorSub (const Vector &ob, const Vector &val, Vector *result) {  for (int x=0; x<VECLEN; ++x)     if (gPred.v[x])       result->v[x] =(ob.v[x] − val.v[x]);     else       result->v[x] &= −gPredFlag; // Not      changed if predicated, 0 if zeroed   return(*result); }

Examples:

 ∼ p 0; a = b − c; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 4 & 2 & 0 & {- 2} & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {b - c}};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 4 & 2 & 0 & {- 2} & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorMult

This instruction performs multiplication on active vector elements.Inactive elements either remain unmodified, or are forced to zero,depending on the nature of the predication. This implementation of theinstruction takes the result vector as an input and performs predicationexplicitly.

Vector VectorMult (const Vector &ob, const Vector &val, Vector *result){   for (int x=0; x<VECLEN; ++x)     if (gPred.v[x])       result->v[x]= (ob.v[x] * val.v[x]);     else       result->v[x] &= −gPredFlag; //Not       changed if predicated, 0 if zeroed   return(*result); }

Examples:

 ∼ p 0; a = b * c; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 12 & 15 & 16 & 15 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {b*c}};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 12 & 15 & 16 & 15 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorDiv

This instruction performs division on active vector elements. Inactiveelements either remain unmodified, or are forced to zero, depending onthe nature of the predication. This implementation of the instructiontakes the result vector as an input and performs predication explicitly.

Vector VectorDiv (const Vector &ob, const Vector &val, Vector *result) {  for (int x=0; x<VECLEN; ++x)     if (gPred.v[x])       result->v[x] =(ob.v[x] / val.v[x]);     else       result->v[x] &= −gPredFlag; // Not      changed if predicated, 0 if Zeroed   return(*result); }

Examples:

 ∼ p 0; a = b/c; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 3 & 1 & 1 & 0 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {b/c}};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 3 & 1 & 1 & 0 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorMod

This instruction performs a modulus operation on active vector elements.Inactive elements either remain unmodified, or are forced to zero,depending on the nature of the predication. This implementation of theinstruction takes the result vector as an input and performs predicationexplicitly.

Vector VectorMod (const Vector &ob, const Vector &val, Vector *result) {  for (int x=0; x<VECLEN; ++x)     if (gPred.v[x])       result->v[x] =(ob.v[x] % val.v[x]);     else       result->v[x] &= −gPredFlag; // Not      changed if predicated, 0 if Zeroed   return(*result); }

Examples:

 ∼ p 0; a = b  %  c; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 0 & 2 & 0 & 3 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {b\mspace{14mu} \% \mspace{14mu} c}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 0 & 2 & 0 & 3 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorAnd

This instruction performs a bitwise “and” on active vector elements.Inactive elements either remain unmodified, or are forced to zero,depending on the nature of the predication. This implementation of theinstruction takes the result vector as an input and performs predicationexplicitly.

Vector VectorAnd (const Vector &ob, const Vector &val, Vector *result) {  for (int x=0; x<VECLEN; ++x)     if (gPred.v[x])       result->v[x] =(ob.v[x] & val.v[x]);     else       result->v[x] &= −gPredFlag; // Not      changed if predicated, 0 if zeroed   return(*result); }

Examples:

 ∼ p 0; a = b  &  c; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 2 & 1 & 4 & 1 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {{b\mspace{14mu}\&}\mspace{14mu} c}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 2 & 1 & 4 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorOr

This instruction performs a bitwise “or” on active vector elements.Inactive elements either remain unmodified, or are forced to zero,depending on the nature of the predication. This implementation of theinstruction takes the result vector as an input and performs predicationexplicitly.

Vector VectorOr (const Vector &ob, const Vector &val, Vector *result) {  for (int x=0; x<VECLEN; ++x)     if (gPred.v[x])       result->v[x] =(ob.v[x] | val.v[x]);     else       result->v[x] &= −gPredFlag; // Not      changed if predicated, 0 if zeroed   return(*result); }

Examples:

 ∼ p 0; a = b|c; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 6 & 7 & 4 & 7 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = \left. b \middle| c \right.};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 6 & 7 & 4 & 7 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorXor

This instruction performs a bitwise “xor” on active vector elements.Inactive elements either remain unmodified, or are forced to zero,depending on the nature of the predication. This implementation of theinstruction takes the result vector as an input and performs predicationexplicitly.

Vector VectorXor (const Vector &ob, const Vector &val, Vector *result) {  for (int x=0; x<VECLEN; ++x)     if (gPred.v[x])       result->v[x] =(ob.v[x] {circumflex over ( )} val.v[x]);     else       result->v[x] &=−gPredFlag; // Not       changed if predicated, 0 if zeroed  return(*result); }

Examples:

${\sim {p\; 0}};{a = {b\hat{}c}};$ ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 4 & 6 & 0 & 6 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {b\hat{}c}};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 4 & 6 & 0 & 6 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorShL

This instruction performs a bitwise left-shift on active vectorelements. Inactive elements either remain unmodified, or are forced tozero, depending on the nature of the predication. This implementation ofthe instruction takes the result vector as an input and performspredication explicitly.

Vector VectorShL (const Vector &ob, const Vector &val, Vector *result) {  for (int x=0; x<VECLEN; ++x)     if (gPred.v[x])       result->v[x] =(ob.v[x] << val.v[x]);     else       result->v[x] &= −gPredFlag; // Not      changed if predicated, 0 if zeroed   return(*result); }

Examples:

 ∼ p 0; a = bc; ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 24 & 40 & 64 & 96 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {bc}};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 24 & 40 & 64 & 96 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorShR

This instruction performs a bitwise right-shift on active vectorelements. Inactive elements either remain unmodified, or are forced tozero, depending on the nature of the predication. This implementation ofthe instruction takes the result vector as an input and performspredication explicitly.

Vector VectorShR (const Vector &ob, const Vector &val, Vector *result) {  for (int x=0; x<VECLEN; ++x)     if (gPred.v[x])       result->v[x] =(ob.v[x] >> val.v[x]);     else       result->v[x] &= −gPredFlag; // Not      changed if predicated, 0 if zeroed   return(*result); }

Examples:

${\sim {p\; 0}};{a = {b\hat{}c}};$ ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 1 & 0 & 0 & 0 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {b\hat{}c}};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 1 & 0 & 0 & 0 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorMin

This instruction performs a “min” operation on active vector elements.Inactive elements either remain unmodified, or are forced to zero,depending on the nature of the predication. As shown below, in someembodiments, the instruction processes all elements equivalently;however, predication is performed by the assignment of the result, andshould be considered an integral part of this instruction.

Vector VectorMin(Vector &a, Vector &b) {   Vector r;   for (int x=0;x<VECLEN; ++x)     if (a.v[x] < b.v[x])       r.v[x] = a.v[x];     else      r.v[x] = b.v[x];   return(r); }

Examples:

 ∼ p 0; a = VectorMin  (b, c); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 2 & 3 & 4 & 3 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {{VectorMin}\mspace{14mu} \left( {b,c} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 2 & 3 & 4 & 3 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorMax

This instruction performs a “max” operation on active vector elements.Inactive elements either remain unmodified, or are forced to zero,depending on the nature of the predication. As shown below, in someembodiments, the instruction processes all elements equivalently;however, predication is performed by the assignment of the result, andshould be considered an integral part of this instruction.

Vector VectorMax(Vector &a, Vector &b) {   Vector r;   for (int x=0;x<VECLEN; ++x)     if (a.v[x] > b.v[x])       r.v[x] = a.v[x];     else      r.v[x] = b.v[x];   return(r); }

Examples:

 ∼ p 0; a = VectorMax  (b, c); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 6 & 5 & 4 & 5 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {{VectorMax}\mspace{14mu} \left( {b,c} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 6 & 5 & 4 & 5 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

Predicate Testing and Manipulation

Some of the following instructions test and generate predicate vectors,setting processor processor status flages to reflect the results. If theinstruction generating the predicates is itself predicated, then theflags reflect the status of the active elements only. Each instructionmay set some or all of the flags, and different instructions setdifferent flags.

  (ZF) NONE - Set if no active elements of the vector are true (PF)ALL - Set if all of the active elements of the vector are true (SF)FIRST - Set if the first active element of the vector is true (OF)LAST - Set if the last active element of the vector is true (CF) CARRY -Set if the last active element of GeneratePredicates( ) output is trueANY - Logical inverse of NONE (!ZF) ABOVE - This condition is calculatedfrom ((CF == 0) && (ZF == 0)) GREATER - Calculated from (ZF == 0) && (SF== OF) LOWER - Calculated from (SF != OF)

VectorTest

This instruction tests the input predicate vector and sets the processorstatus flags accordingly.

-   -   gNone NONE—Used to indicates that no active predicates have been        set    -   gFirst FIRST—Used to indicate that the first active predicates        is set    -   gLast LAST—Used to indicates that the last active predicate is        set    -   gAll ALL—Used to indicate that all active predicates are set

Flags: ZF - Set if no active elements are true. Cleared otherwise.SF/OF/PF - Indicates whether the First/Last/All active elements of theresult are true. void VectorTest(Vector &p) {   int x,s,t;   s = 0;  for (x=0; x<VECLEN; ++x)   {     s = (gPred.v[x] && p.v[x]);     if(gPred.v[x])     break;   }   gFirst = s;   s = 0;   for (x=VECLEN−1;x>=0; −−x)   {     s = (gPred.v[x] && p.v[x]);     if (gPred.v[x])    break;   }   gLast = s;   s = t = 0;   for (x=0; x<VECLEN; ++x)   {    t += (gPred.v[x]);     s += (gPred.v[x] && p.v[x]);   }   gNone = (s== 0);   gAll = (s == t);   return; }

VectorEQ

This instruction compares active vector elements and returns a resultvector indicating whether the elements of the first parameter are equalto elements of the second parameter. Inactive elements either remainunmodified, or are forced to zero, depending on the nature of thepredication. This implementation of the instruction takes the resultvector as an input and performs predication explicitly.

Flags: ZF - Set if no active elements are true. Cleared otherwise.SF/OF/PF - Indicates whether the First/Last/All active elements of theresult are true. Vector VectorEQ (const Vector &ob, const Vector &val) {  Vector result;   for (int x=0; x<VECLEN; ++x)     result.v[x] =(ob.v[x] == val.v[x]);   VectorTest(result);   return(result); }

Examples:

 ∼ p 0; a = (b =  = c); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 0 & 0 & 1 & 0 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = \left( {b==c} \right)};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 0 & 0 & 1 & 0 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorGT

This instruction compares active vector elements and returns a resultvector indicating whether the elements of the first parameter aregreater-than elements of the second parameter. Inactive elements eitherremain unmodified, or are forced to zero, depending on the nature of thepredication. This implementation of the instruction takes the resultvector as an input and performs predication explicitly.

Flags: ZF - Set if no active elements are true. Cleared otherwise.SF/OF/PF - Indicates whether the First/Last/All active elements of theresult are true. Vector VectorGT (const Vector &ob, const Vector &val) {  Vector result;   for (int x=0; x<VECLEN; ++x)     result.v[x] =(ob.v[x] > val.v[x]);   VectorTest(result);   return(result); }

Examples:

 ∼ p 0; a = (b > c); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 1 & 1 & 0 & 0 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = \left( {b > c} \right)};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 0 & 0 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorGE

This instruction compares active vector elements and returns a resultvector indicating whether the elements of the first parameter aregreater-than or equal-to elements of the second parameter. Inactiveelements either remain unmodified, or are forced to zero, depending onthe nature of the predication. This implementation of the instructiontakes the result vector as an input and performs predication explicitly.

Flags: ZF - Set if no active elements are true. Cleared otherwise.SF/OF/PF - Indicates whether the First/Last/All active elements of theresult are true. Vector VectorGE (const Vector &ob, const Vector &val) {  Vector result;   for (int x=0; x<VECLEN; ++x)     result.v[x] =(ob.v[x] >= val.v[x]);   VectorTest(result);   return(result); }

Examples:

 ∼ p 0; a = (b >  = c); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 9 & 1 & 1 & 1 & 0 & 9 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = \left( {b>=c} \right)};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 1 & 0 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \begin{Bmatrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \left\{ \begin{matrix}8 & 7 & 6 & 5 & 4 & 3 & 2 & \left. 1 \right\}\end{matrix} \right.} \\\; & {c = \left\{ \begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & \left. 7 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 0 & 1 & 1 & 1 & 0 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

VectorNEQ

This instruction compares active vector elements and returns a resultvector indicating whether the elements of the first parameter arenon-equal to elements of the second parameter. Inactive elements eitherremain unmodified, or are forced to zero, depending on the nature of thepredication. This implementation of the instruction takes the resultvector as an input and performs predication explicitly.

Flags: ZF - Set if no active elements are true. Cleared otherwise.SF/OF/PF - Indicates whether the First/Last/All active elements of theresult are true. Vector VectorNEQ (const Vector &ob, const Vector &val){   Vector result;   for (int x=0; x<VECLEN; ++x)     result.v[x] =(ob.v[x] != val.v[x]);   VectorTest(result);   return(result); }

Examples:

 ∼ p 0; a = (b ! = c); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1 & \} \\\; & c & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 9 & 9 & 1 & 1 & 0 & 1 & 9 & 9 & \}\end{matrix}!}{p\; 0}};{a = \left( {b!=c} \right)};$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1 & \} \\\; & c & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 0 & 1 & 1 & 0 & 1 & 0 & 0 & \}\end{matrix}$

Continue

This instruction logically negates active vector elements. Inactiveelements either remain unmodified, or are forced to zero, depending onthe nature of the predication. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction.

Flags: ZF - Set if no active elements are true. Cleared otherwise.SF/OF/PF - Indicates whether the First/Last/All active elements of theresult are true. Vector Continue(Vector &p) {   Vector r;   for (intx=0; x<VECLEN; ++x)     r.v[x] = !p.v[x];   VectorTest(r);   return(r);}

Examples:

 ∼ p 0; a = Continue  (b); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & {- 2} & {- 1} & 0 & 1 & 2 & 3 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 9 & 9 & 0 & 1 & 0 & 0 & 9 & 9 & \}\end{matrix}!}p\; 0};{a = {{Continue}\mspace{14mu} (b)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & {- 2} & {- 1} & 0 & 1 & 2 & 3 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & \}\end{matrix}$

Break

This instruction returns a vector containing ones in all positionsbefore the first non-zero element position of its input, and zeroes allother positions. Predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.

Flags: ZF - Set if no active elements are true. Cleared otherwise.SF/OF/PF - Indicates whether the First/Last/All active elements of theresult are true. Vector Break(Vector &p) {   Vector r = 0;   for (intx=0; x<VECLEN; ++x)   {     if (p.v[x])       break;     r.v[x] = 1;   }  VectorTest(r);   return(r); }

Examples:

 ∼ p 0; a = Break  (b); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 9 & 9 & 1 & 1 & 0 & 0 & 9 & 9 & \}\end{matrix}!}p\; 0};{a = {{Break}\mspace{14mu} (b)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & \}\end{matrix}$

PreBreak

This instruction returns a vector containing zeroes in all positionsafter the first non-zero element position of its input, and ones in allother positions. Predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.

Flags: ZF - Set if no active elements are true. Cleared otherwise.SF/OF/PF - Indicates whether the First/Last/All active elements of theresult are true. Vector PreBreak(Vector &p) {   Vector r = 0;   for (intx=0; x<VECLEN; ++x)   {     r.v[x] = 1;     if (p.v[x])       break;   }  VectorTest(r);   return(r); }

Examples:

 ∼ p 0; a = PreBreak  (b); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 9 & 9 & 1 & 1 & 1 & 0 & 9 & 9 & \}\end{matrix}!}p\; 0};{a = {{{Pre}{Break}}\mspace{14mu} (b)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & \}\end{matrix}$

Remaining

This instruction sets all elements after the last non-zero element to 1,and all other elements to zero. An input vector of all zero elementsreturns all ones, and a vector of all non-zero returns all zeroes. Asshown below, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.

Flags: ZF - Set if no active elements are true. Cleared otherwise.SF/OF/PF - Indicates whether the First/Last/All active elements of theresult are true. Vector Remaining(Vector &p) {   Vector r = 0;   int x;  for (x=VECLEN−1; x>=0; −−x)     if (p.v[x])       break;   ++x;   if(x== VECLEN)     x = 0;   for (; x<VECLEN; ++x)     r.v[x] = 1;  VectorTest(r);   return(r); }

 ∼ p 0; a = Remaining  (b); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 9 & 9 & 0 & 0 & 1 & 1 & 9 & 9 & \}\end{matrix}!}p\; 0};{a = {{Remaining}\mspace{14mu} (b)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & 1 & 0 & 1 & 0 & 0 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & \}\end{matrix}$

GeneratePredicates

This instruction takes a dependency index vector, DIV, and generatespredicates corresponding to the next group of elements that may safelybe processed in parallel, given the previous group that was processedwhich is indicated by prey. If no elements of prey are active,predicates are generated for the first group of elements that may safelybe processed in parallel. If prey indicates that the final elements ofthe vector have been processed, then a result vector of inactivepredicates is returned. The definition of GeneratePredicates follows. Asshown below, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.(Note that GeneratePredicates uses the destination register as one ofits inputs.)

Flags: ZF - Set if no active elements are true. Cleared otherwise.SF/OF/PF - Indicates whether the First/Last/All active elements of theresult are true CF - Indicates Last or None (CF = OF || ZF) VectorGeneratePredicates(Vector &prev, Vector &index) {   Vector r = 0;   intx, pos;   for (pos=VECLEN−1; pos>=0; −−pos)     if (prev.v[pos])    break;   for (++pos; pos<VECLEN; ++pos) // start at next   activeposition     if (gPred.v[pos])       break;   for (x=pos; x<VECLEN; ++x)  {     if (index.v[x] > pos) // compare DIV (1-     based) value toposition (0-based)       break;     r.v[x] = 1;   }   VectorTest(r);  gCarry = gLast || gNone;   return(r); }

Examples:

 ∼ p 0; p 1 = GeneratePredicates(p 1, ix); $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \} \\\; & {ix} & = & \{ & 0 & 0 & 0 & 2 & 1 & 3 & 4 & 0 & \} \\{{On}\mspace{14mu} {{Exit}1}\text{:}} & {p\; 1} & = & \{ & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & \}\end{matrix}$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 1} & = & \{ & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & \} \\{{On}\mspace{14mu} {{Exit}2}\text{:}} & {p\; 1} & = & \{ & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & \}\end{matrix}$ ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 1} & = & \{ & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & \} \\{{On}\mspace{14mu} {{Exit}3}\text{:}} & {p\; 1} & = & \{ & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & \}\end{matrix}!}p\; 0};{{p\; 1} = {{GeneratePredicates}\left( {{p\; 1},{ix}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \} \\\; & {ix} & = & \{ & 0 & 0 & 0 & 2 & 1 & 3 & 4 & 0 & \} \\{{On}\mspace{14mu} {{Exit}1}\text{:}} & {p\; 1} & = & \{ & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & \}\end{matrix}$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 1} & = & \{ & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & \} \\{{On}\mspace{14mu} {{Exit}2}\text{:}} & {p\; 1} & = & \{ & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & \}\end{matrix}$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 1} & = & \{ & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & \} \\{{On}\mspace{14mu} {{Exit}3}\text{:}} & {p\; 1} & = & \{ & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & \}\end{matrix}$

Actual

This instruction is employed by loops that use first-faultinginstructions in speculation, in order to determine which elements wereactually processed without masked faults, and narrow the vector sizedown to elements that are not affected by the masked faults. Thisinstruction calculates which elements specified by the predicateparameter p have been processed without any faulting conditions. This isaccomplished by consulting the fault-status register (see thedescription of the fault-status register, above), and turning off (i.e.,zeroing) elements of p that have either exhibited a faulting condition,or are in positions higher than an element that has exhibited a faultingcondition. This instruction also resets the FSR registers to theirdefault condition.

Flags: ZF - Set if no active elements of the result are true. Clearedotherwise SF/OF/PF - Indicates whether the First/Last/All activeelements of the result are true. CF - Indicates Last or None (CF = OF ||ZF) FSR - Reset to default (no faulting conditions). Vector Actual(constVector &p) {  Vector r = 0;  int x;  for (x=0; x<VECLEN; ++x)  if(gFSR[x] && gPred.v[x]) break;  else r.v[x] = p.v[x];  VectorTest(r); gCarry = gLast || gNone;  ResetFSR( );  return(r); }

Examples:

 ∼ p 0; a = Actual  (b); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {FSR} & = & \{ & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & \} \\\; & {p\; 0} & = & \{ & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & 1 & 0 & 1 & 1 & 1 & 0 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 9 & 1 & 0 & 1 & 1 & 0 & 0 & 9 & \} \\\; & {FSR} & = & \{ & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \}\end{matrix}!}p\; 0};{a = {{Actual}\mspace{14mu} (b)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {FSR} & = & \{ & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & \} \\\; & {p\; 0} & = & \{ & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & 1 & 0 & 1 & 1 & 1 & 0 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 1 & 0 & 1 & 1 & 0 & 0 & 0 & \} \\\; & {FSR} & = & \{ & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \}\end{matrix}$

ActualFault1

This instruction is employed by loops that employ All-Faultinginstructions in speculation and use Soft-Terminate Mode to avoidpremature termination of the program. The ActualFault1 instruction isused where code is expected to execute when the loop terminationcondition is true, such as Do-While loops or after a PreBreakinstruction. This instruction checks the loop-termination predicate pagainst the FSR and generates an exception if program should beterminated. This instruction also resets the FSR to its default state.This instruction does not modify any flags or registers.

Flags: FSR - Reset to default state. void ActualFault1(const Vector &p){   int x,s;   for (s=0; s<VECLEN; ++s)     if (gPred.v[s])       break;  for (x=s; x<VECLEN; ++x)     if (gPred.v[x] && gFSR[x])     {       if(p.v[x])         TriggerFault(“ActualFault1”);       break;     }  ResetFSR( );   return; }

ActualFault2

This instruction is employed by loops that employ All-Faultinginstructions in speculation and use Soft-Terminate Mode to avoidpremature termination of the program. The ActualFault2 instruction isused where execution is not expected when the loop termination conditionis true, such as While-Do loops or after a Break instruction. Thisinstruction checks the loop-termination predicate p against the FSR andgenerates an exception if program should be terminated. This instructionalso resets the FSR to its default state. This instruction does notmodify any flags or registers.

Flags: FSR - Reset to default state. void ActualFault2(const Vector &p){   int x,s;   for (s=0; s<VECLEN; ++s)     if (gPred.v[s])      break;  for (x=s; x<VECLEN; ++x)     if (gPred.v[x] && gFSR[x])     {       if(x > s)         if (p.v[x−1] && gPred.v[x−1])          TriggerFault(“ActualFault2”);       if (p.v[x])        TriggerFault(“ActualFault2”);       break;     }   ResetFSR( );  return; }

Hazard-Checking Instructions

The hazard-checking instructions enable a compiler to generate code thatpartitions the vector at run-time according to dynamic data andcontrol-flow hazards that are unpredictable at compile time.

CheckHazardP

This instruction examines two vectors of memory addresses (or arrayindices), corresponding to two memory operations, for potential datadependencies through memory. The vector first holds addresses for thefirst memory operation, and the vector second holds addresses for thesecond operation. The predicate pred indicates which elements of secondare to be operated upon. This instruction checks for addresses thatoverlap between each element of first and lower-numbered elements ofsecond. In the case of multiple matches, only the highest-numberedposition is recorded. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction.

The 1-based element position corresponding to the iteration thatgenerates the data that is depended upon is stored in the destinationvector at the element position corresponding to the iteration that isdependent upon the data. If no data dependency exists, a zero is storedin the destination vector at the element position corresponding to theiteration that does not have the dependency. Variants of thisinstruction should account for overlap between various sizes of datatypes.

The CheckHazardP instruction only supports zeroing predication.Non-zeroing predication is not allowed.

Vector CheckHazardP(Vector &first, Vector &second, Vector &p) {   Vectorresult = 0;   int x,y;   for (x=0; x<VECLEN; ++x)     for (y=0; y<x;++y)      if (p.v[y])       if (OVERLAP(first.v[x], second.v[y]))        result.v[x] = y + 1;   return(result); }

Examples:

\!p 0; a = CheckHazardP(b, c, p 1); $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 1 & 2 & 1 & 2 & 2 & 1 & 5 & 6 & \} \\\; & c & = & \{ & 1 & 1 & 2 & 2 & 4 & 5 & 6 & 7 & \} \\\; & {p\; 1} & = & \{ & 1 & 1 & 0 & 1 & 1 & 1 & 1 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 0 & 2 & 0 & 4 & 2 & 0 & 0 & \}\end{matrix}$

CheckHazardPx

This instruction examines two vectors of memory addresses (or arrayindices), corresponding to two memory operations, for potential datadependencies through memory. The vector first holds addresses for thefirst memory operation, and vector second holds addresses for the secondoperation. The predicate pred indicates which elements of second are tobe operated upon. This instruction checks for addresses that overlapbetween each element of first, and lesser-or-equal-numbered elements ofsecond. In the case of multiple matches, only the highest-numberedposition is recorded. In the case of a match against an equal-numberedelement position, the dependency is recorded in the next-highestposition in the result. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction.

The 1-based element position corresponding to the iteration thatgenerates the data that is depended upon is stored in the destinationvector at the element position corresponding to the iteration that isdependent upon the data. If no data dependency exists, a zero is storedin the destination vector at the element position corresponding to theiteration that does not have the dependency. Variants of thisinstruction should account for overlap between various sizes of datatypes.

The CheckHazardPX instruction only supports zeroing predication.Non-zeroing predication is not allowed.

Vector CheckHazardPx(Vector &first, Vector &second, Vector &p) {  Vector result = 0;   int x,y;   for (x=1; x<VECLEN; ++x)   {     for(y=0; y<x; ++y)       if (p.v[y])         if (OVERLAP(first.v[x],   second.v[y]))           result.v[x] = y + 1;       if((OVERLAP(first.v[x−1], second.v[x−       1]) && p.v[x−1]))        result.v[x] = x;   }   return(result); }

Examples:

\!p 0; a = CheckHazardPx(b, c, p 1); $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 1 & 1 & 2 & 2 & 5 & 6 & 3 & 6 & \} \\\; & c & = & \{ & 1 & 2 & 2 & 3 & 4 & 5 & 6 & 6 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 0 & 2 & 3 & 0 & 0 & 4 & 0 & \}\end{matrix}$

ConditionalStop

This instruction takes the scalar parameter mode, which indicates anynumber of four possible transitions between true and false values ofadjacent elements in predicate p that imply data dependencies. Theparameter mode is a 4-bit field, the bits of which are defined asfollows:

-   -   kTF—Implies a loop-carried dependency from an iteration for        which the predicate is true, to the subsequent iteration for        which the value of the predicate is false.    -   kFF—Implies a loop-carried dependency from an iteration for        which the predicate is false, to the subsequent iteration for        which the value of the predicate is false.    -   kFT—Implies a loop-carried dependency from an iteration for        which the predicate is false, to the subsequent iteration for        which the value of the predicate is true.    -   kTT—Implies a loop-carried dependency from an iteration for        which the predicate is true, to the subsequent iteration for        which the value of the predicate is true.

The 1-based (i.e., considering the vector as starting with element “1”)element position corresponding to the iteration that generates the datathat is depended upon is stored in the destination vector at the elementposition corresponding to the iteration that depends on the data. If nodata dependency exists, a value of 0 is stored in the destination vectorat that element. Note that the ConditionalStop instruction supports onlyzeroing; non-zeroing predication is illegal.

Vector ConditionalStop(Vector &p, int mode) {   Vector r = 0;   for (intx=1; x<VECLEN; ++x) // Skip the first   element   {     if (p.v[x−1] ==0 && p.v[x] == 0)     {       if (mode & kFF)         r.v[x] = x;     }    else if (p.v[x−1] == 0 && p.v[x] == 1)     {       if (mode & kFT)        r.v[x] = x;     }     else if (p.v[x−1] == 1 && p.v[x] == 0)    {       if (mode & kTF)         r.v[x] = x;     }     else     {      if (mode & kTT)         r.v[x] = x;     }   }   return(r); }

Examples:

\!p 0; a = ConditionalStop(b, kTF|kFT); $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 0 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 0 & 2 & 3 & 0 & 5 & 0 & 0 & \}\end{matrix}$

Value Copy Propagation PropagatePostT

This instruction propagates the value of active elements in s, asdetermined by predicate p, to subsequent inactive elements in thedestination. Active elements remain unchanged, and any inactive elementsthat precede the first active element also remain unchanged. As shownbelow, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that the PropagatePostT uses the destination register as one if itsinputs.

Vector PropagatePostT(Vector &d, Vector &s, Vector &p) {   Vector r = 0;  int x,y;   for (x=0; x<VECLEN; ++x) // Until first active   predicate,preserve dest   {     y = x;     r.v[x] = d.v[x];     if (gPred.v[x] &&p.v[x])       break;   }   for (++x; x<VECLEN; ++x)     if (gPred.v[x]&& p.v[x])     {       r.v[x] = d.v[x]; // While predicate ==       1,preserve dest       y = x;     }     else       r.v[x] = s.v[y]; //While predicate ==       0, copy final from source   return(r); }

Examples:

 ∼ p 0; a = PropagatePostT(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & \} \\\; & a & = & \{ & 8 & 9 & A & B & C & D & E & F & \} \\\; & b & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 8 & 9 & A & B & 3 & 3 & E & 6 & \}\end{matrix}!}p\; 0};{a = {{PropagatePostT}\left( {a,b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & \} \\\; & a & = & \{ & 8 & 9 & A & B & C & D & E & F & \} \\\; & b & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 9 & A & B & 3 & 3 & E & 6 & \}\end{matrix}$

PropagatePriorF

This instruction propagates the value of the inactive elements of src,as determined by predicate p, into subsequent active elements. Inactiveelements are copied from src to the destination. If the first element ofpredicate is active, then the last element of src is propagated to thatposition. As shown below, in some embodiments, the instruction processesall elements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction.

Vector PropagatePriorF(Vector &src, Vector &p) {   Vector r = 0;   intx,y;   y = VECLEN − 1; // y is position of element to   propagate   for(x=0; x<VECLEN; ++x) // Destination unchanged   until first activepredicate   {     if (gPred.v[x] && p.v[x])       break;     r.v[x] =src.v[x];     y = x;   }   for (; x<VECLEN; ++x)   {     if (gPred.v[x]&& p.v[x])     {       r.v[x] = src.v[y]; // Propagate on       activepredicates     }     else     {       r.v[x] = src.v[x]; // Copy oninactive       predicates       y = x;     }   }   return(r); }

Examples:

 ∼ p 0; a = PropagatepPriorF(b, p 1); $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 9 & 2 & 2 & 2 & 5 & 6 & 6 & 9 & \}\end{matrix}$ ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 8 & 8 & 3 & 3 & 5 & 6 & 6 & 9 & \}\end{matrix}!}p\; 0};{a = {{PropagatepPriorF}\left( {b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 2 & 2 & 2 & 5 & 6 & 6 & 0 & \}\end{matrix}$ $\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 1 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 8 & 8 & 3 & 3 & 5 & 6 & 6 & 0 & \}\end{matrix}$

CopyPropagate

This instruction copies active elements, as determined by p, from src tothe destination register. Active elements are propagated into inactiveelements in the process. Any initial inactive elements remain unchangedin the destination. As shown below, in some embodiments, the instructionprocesses all elements equivalently; however, predication is performedby the assignment of the result, and should be considered an integralpart of this instruction. Note that CopyPropagate uses the destinationregister as one of its inputs.

Vector CopyPropagate(Vector &dest, Vector &src, Vector &p) {  Vector r; int x,y;  y = 0;  for (x=0; x<VECLEN; ++x) // Find first active  pred,dest unchanged   if (p.v[x] && gPred.v[x])    break;   else   {   r.v[x] = dest.v[x];    y = x;   }  for (; x<VECLEN; ++x) // Ifactive: copy. If  inactive: propagate  {   if (p.v[x] && gPred.v[x])   {   r.v[x] = src.v[x];    y = x;   }   else    r.v[x] = src.v[y];  } return(r); }

Examples:

 ∼ p 0; a = CopyProgate(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 9 & 9 & 3 & 4 & 4 & 4 & 7 & 7 & \}\end{matrix}!}p\; 0};{a = {{CopyPropagate}\left( {a,b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 9 & 3 & 4 & 4 & 4 & 7 & 7 & \}\end{matrix}$

ShiftInRightP

This instruction shifts vector elements to the right, or propagatesactive values, as determined by input predicate p. The first activeelement receives the input scalar j. The resulting vector is stored tothe destination register. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction.

Vector ShiftInRightP(int j, const Vector &v, int &p) {  Vector r = 0; int x;  r = v;  for(x=0; x<VECLEN; ++x)   if(gPred.v[x])    break; r.v[x] = j;  for (++x; x<VECLEN; ++x)  {   if (gPred.v[x] && p.v[x−1])   r.v[x] = v.v[x−1];   else if (gPred.v[x])    r.v[x] = r.v[x−1];  else    r.v[x] = v.v[x−1];  }  return(r); }

Examples:

 ∼ p 0; a = ShiftInRightP(j, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & j & = & {\; 9} & \; & \; & \; & \; & \; & \; & \; & \; & \; \\\; & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & \} \\\; & a & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 1 & 2 & 9 & 3 & 4 & 4 & 4 & 7 & \}\end{matrix}!}p\; 0};{a = {{ShiftInRightP}\left( {j,b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & j & = & {\; 9} & \; & \; & \; & \; & \; & \; & \; & \; & \; \\\; & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & \} \\\; & a & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 0 & 9 & 3 & 4 & 4 & 4 & 7 & \}\end{matrix}$

ShiftInRight

This instruction shifts vector elements to the right, or propagatesactive values, as determined by input predicate p. The first elementreceives the input scalar j. The resulting vector is stored to thedestination register. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction.

Vector ShiftInRight(int j, const Vector &v, int &p) {  Vector r = 0; int x;  r.v[0] = j;  for (x=1; x<VECLEN; ++x)  {   if (gPred.v[x] &&p.v[x−1])    r.v[x] = v.v[x−1];   else if (gPred.v[x])    r.v[x] =r.v[x−1];   else    r.v[x] = v.v[x−1];  }  return(r); }

Examples:

 ∼ p 0; a = ShiftInRightP(j, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & j & = & {\; 9} & \; & \; & \; & \; & \; & \; & \; & \; & \; \\\; & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & \} \\\; & a & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 1 & 2 & 9 & 3 & 4 & 4 & 4 & 7 & \}\end{matrix}!}p\; 0};{a = {{ShiftInRightP}\left( {j,b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & j & = & {\; 9} & \; & \; & \; & \; & \; & \; & \; & \; & \; \\\; & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & \} \\\; & a & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 0 & 9 & 3 & 4 & 4 & 4 & 7 & \}\end{matrix}$

ShiftRight

This instruction shift vector elements to the right, populating thefirst element with the input scalar j. The resulting vector is stored tothe destination register.

Vector ShiftInRight(int j, const Vector &v) {  Vector r = 0;  int x; r.v[0] = j;  for (++x; x<VECLEN; ++x)  {   r.v[x] = v.v[x−1];  } return(r); }

Examples:

 ∼ p 0; a = ShiftRight(j, b); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & j & = & 9 & \; & \; & \; & \; & \; & \; & \; & \; & \; \\\; & {p\; 0} & = & \{ & 1 & 1 & 1 & 0 & 0 & 1 & 1 & 1 & \} \\\; & a & = & \{ & A & A & A & A & A & A & A & A & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 9 & 1 & 2 & A & A & 5 & 6 & 7 & \}\end{matrix}!}p\; 0};{a = {{ShiftRight}\left( {j,b} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & j & = & 9 & \; & \; & \; & \; & \; & \; & \; & \; & \; \\\; & {p\; 0} & = & \{ & 1 & 1 & 1 & 0 & 0 & 1 & 1 & 1 & \} \\\; & a & = & \{ & A & A & A & A & A & A & A & A & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 9 & 1 & 2 & 0 & 0 & 5 & 6 & 7 & \}\end{matrix}$

SelectLast

Use of the ShiftInRightP instruction often requires that the shifted-outelement be captured to be shifted in during the next pass. Normally thisis accomplished using a simple scalar cast prior to the use ofShiftInRightP. In cases where the shifted-out value may come from morethan one vector under control of predication, the SelectLast instructionis used to capture the last element from one of two vectors. Note thatthe final active element determines which element position p isevaluated for. This instruction is also useful at the end of nestedloops and when consolidating vectors back into scalar variables at theend of a loop, or within loops that call functions that may referenceglobal scalar variables.

int SelectLast(cont Vector &v1, const Vector &v2, const Vector &p) { Vector r = 0;  int x;  for (x=VECLEN−1; x>=0; −−x)   if (gPred.v[x])   break;  if (x >= 0)   if (p.v[x])    r = v2.v[x];   else    r =v1.v[x];  return(r); }

Examples:

 ∼ p 0; a = SelectLast(b, c, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & a & = & 9 & \; & \; & \; & \; & \; & \; & \; & \; & \; \\\; & {p\; 0} & = & \{ & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & \} \\\; & a & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & b & = & \{ & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & {\; 6} & \; & \; & \; & \; & \; & \; & \; & \; & \;\end{matrix}!}p\; 0};{a = {{SelectLast}\left( {b,c,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & a & = & 9 & \; & \; & \; & \; & \; & \; & \; & \; & \; \\\; & {p\; 0} & = & \{ & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & c & = & \{ & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & {\; 4} & \; & \; & \; & \; & \; & \; & \; & \; & \;\end{matrix}$

SelectFirst

The SelectFirst instruction selects the first actively predicated fromeither v1 or v2, as determined by the value of corresponding element inp. This instruction is useful at the end of nested loops and whenconsolidating vectors back into scalar variables at the end of a loop,or within loops that call functions that may reference global scalarvariables.

int SelectFirst(cont Vector &v1, const Vector &v2, const Vector &p) { Vector r = 0;  int x;  for (x=0; x<VECLEN; ++x)   if (gPred.v[x])   break;  if (p.v[x])   r = v2.v[x];  else   r = v1.v[x];  return(r); }

Examples:

 ∼ p 0; a = SelectFirst(b, c, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & a & = & 9 & \; & \; & \; & \; & \; & \; & \; & \; & \; \\\; & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & c & = & \{ & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & {\; 3} & \; & \; & \; & \; & \; & \; & \; & \; & \;\end{matrix}!}p\; 0};{a = {{SelectFirst}\left( {b,c,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & a & = & 9 & \; & \; & \; & \; & \; & \; & \; & \; & \; \\\; & {p\; 0} & = & \{ & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & c & = & \{ & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & \} \\\; & {p\; 1} & = & \{ & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 1 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & {\; 7} & \; & \; & \; & \; & \; & \; & \; & \; & \;\end{matrix}$

Associative Reduction Operations

By encapsulating conditionally executed associative reductionoperations, these instructions allow the compiler to eliminate someloop-carried dependencies altogether, replacing them with the singlevector instruction that can be executed in parallel. Each of theseinstructions comes in two variants. One variant produces a vector ofresult values corresponding to the reduction value just before theoperation is applied. The other variant produces a vector of resultvalues corresponding to the reduction value just after the operation isapplied. Both variants are often needed to vectorize loops.

IncrPropagate1

Using the value of the first active element in s as a basis, thisinstruction cumulatively increments this basis for every active elementspecified by predicate p. Inactive elements prior to the first activeelements are copied into the destination. This instruction stores thevalues prior to being incremented into the destination register. Asshown below, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.

Vector IncrPropagate1(Vector &s, Vector &p) {   Vector r;   int x,v;  for (x=0; x<VECLEN; ++x)   {     if (gPred.v[x] && p.v[x])     {      v = s.v[x];       break;     }     r.v[x] = s.v[x];   }   for (;x<VECLEN; ++x)   {     r.v[x] = v;     if (gPred.v[x] && p.v[x])      ++v;   }   return(r); }

Examples:

 ∼ p 0; a = IncrPropagate  1(b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 3 & 3 & 3 & 3 & 3 & 3 & 3 & 3 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 3 & 3 & 4 & 5 & 5 & 5 & 6 & 9 & \}\end{matrix}!}p\; 0};{a = {{IncrPropagate}\mspace{11mu} 1\left( {b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 3 & 3 & 3 & 3 & 3 & 3 & 3 & 3 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 3 & 3 & 4 & 5 & 5 & 5 & 6 & 0 & \}\end{matrix}$

IncrPropagate2

Using the value of the first active element in s as a basis, thisinstruction cumulatively increments this basis for every active elementspecified by predicate p. Inactive elements prior to the first activeelements are copied into the destination. This instruction stores thevalues after being incremented into the destination register. As shownbelow, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.

Vector IncrPropagate2(Vector &s, Vector &p) {   Vector r;   int x,v;  for (x=0; x<VECLEN; ++x)   {     if (gPred.v[x] && p.v[x])     {      v = s.v[x];       break;     }     r.v[x] = s.v[x];   }   for (;x<VECLEN; ++x)   {     if (gPred.v[x] && p.v[x])       ++v;     r.v[x] =v;   }   return(r); }

Examples:

 ∼ p 0; a = IncrPropagate  2(b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 3 & 3 & 3 & 3 & 3 & 3 & 3 & 3 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 3 & 4 & 5 & 5 & 5 & 6 & 7 & 9 & \}\end{matrix}!}p\; 0};{a = {{IncrPropagate}\mspace{11mu} 2\left( {b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 3 & 3 & 3 & 3 & 3 & 3 & 3 & 3 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 3 & 4 & 5 & 5 & 5 & 6 & 7 & 0 & \}\end{matrix}$

DecrPropagate1

Using the value of the first active element in s as a basis, thisinstruction cumulatively decrements this basis for every active elementspecified by predicate p. Inactive elements prior to the first activeelements are copied into the destination. This instruction stores thevalues prior to being decremented into the destination register. Asshown below, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.

Vector DecrPropagate1(Vector &s, Vector &p) {   Vector r;   int x,v;  for (x=0; x<VECLEN; ++x)   {     if (gPred.v[x] && p.v[x])     {      v = s.v[x];       break;     }     r.v[x] = s.v[x];   }   for (;x<VECLEN; ++x)   {     r.v[x] = v;     if (gPred.v[x] && p.v[x])      −−v;   }   return(r); }

Examples:

 ∼ p 0; a = DecrPropagate  1 (b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 7 & 7 & 7 & 7 & 7 & 7 & 7 & 7 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 7 & 7 & 6 & 5 & 5 & 5 & 4 & 9 & \}\end{matrix}!}p\; 0};{a = {{DecrPropagate}\mspace{11mu} 1\left( {b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 7 & 7 & 7 & 7 & 7 & 7 & 7 & 7 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 7 & 7 & 6 & 5 & 5 & 5 & 4 & 0 & \}\end{matrix}$

DecrPropagate2

Using the value of the first active element in s as a basis, thisinstruction cumulatively decrements this basis for every active elementspecified by predicate p. Inactive elements prior to the first activeelements are copied into the destination. This instruction stores thevalues after being decremented into the destination register. As shownbelow, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.

Vector DecrPropagate2(Vector &s, Vector &p) {   Vector r;   int x,v;  for (x=0; x<VECLEN; ++x)   {     if (gPred.v[x] && p.v[x])     {      v = s.v[x];       break;     }     r.v[x] = s.v[x];   }   for (;x<VECLEN; ++x)   {     if (gPred.v[x] && p.v[x])       −−v;     r.v[x] =v;   }   return(r); }

Examples:

 ∼ p 0; a = DecrPropagate  2 (b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 7 & 7 & 7 & 7 & 7 & 7 & 7 & 7 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 7 & 6 & 5 & 5 & 5 & 4 & 3 & 9 & \}\end{matrix}!}p\; 0};{a = {{DecrPropagate}\mspace{11mu} 2\left( {b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 9 & 9 & 9 & 9 & 9 & 9 & 9 & 9 & \} \\\; & b & = & \{ & 7 & 7 & 7 & 7 & 7 & 7 & 7 & 7 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 7 & 6 & 5 & 5 & 5 & 4 & 3 & 0 & \}\end{matrix}$

RunningSum1P

Using the value of the first active element in a as a basis, thisinstruction adds the cumulative amounts specified by active elements inb to this basis. Predicate p determines which elements participate inthe accumulation of addends. Inactive elements prior to the first activeelements are copied into the destination. This instruction stores thevalues prior to being added into the destination register. As shownbelow, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that the RunningSum1P instruction uses the destination register asone of its inputs.

Vector RunningSum1P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if ((gPred.v[x]) && (p.v[x]))       s += b.v[x];   }  return(r); }

Examples:

 ∼ p 0; a = RunningSum  1P  (a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 1 & 1 & 4 & 4 & 5 & 9 & 7 & \}\end{matrix}!}p\; 0};{a = {{RunningSum}\mspace{11mu} 1P\mspace{11mu} \left( {a,b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 1 & 1 & 4 & 4 & 0 & 9 & 0 & \}\end{matrix}$

RunningSum2P

Using the value of the first active element in a as a basis, thisinstruction adds the cumulative amounts specified by active elements inb to this basis. Predicate p determines which elements participate inthe accumulation of addends. Inactive elements prior to the first activeelements are copied into the destination. This instruction stores thevalues after being added into the destination register. As shown below,in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that the RunningSum2P instruction uses the destination register asone of its inputs.

Vector RunningSum2P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))       s += b.v[x];     r.v[x] = s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningSum  2P  (a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 1 & 1 & 4 & 4 & 9 & 5 & 16 & 7 & \}\end{matrix}!}p\; 0};{a = {{RunningSum}\mspace{11mu} 2P\mspace{11mu} \left( {a,b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 1 & 1 & 4 & 4 & 9 & 0 & 16 & 0 & \}\end{matrix}$

RunningSub1P

Using the value of the first active element in a as a basis, thisinstruction subtracts the amounts in active elements in b from thisbasis. Predicate (control vector) p determines which elementsparticipate in the subtraction operation. Inactive elements prior to thefirst active elements are copied into the destination. This instructionstores the values prior to being subtracted into the destinationregister. As shown below, in some embodiments, the instruction processesall elements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that the RunningSub1P instruction uses thedestination register as one of its inputs.

Vector RunningSub1P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if ((gPred.v[x]) && (p.v[x]))       s −= b.v[x];   }  return(r); }

Examples:

 ∼ p 0; a = RunningSub  1P  (a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 14 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 14 & 13 & 13 & 10 & 10 & 5 & 5 & 7 & \}\end{matrix}!}p\; 0};{a = {{RunningSub}\mspace{11mu} 1P\mspace{11mu} \left( {a,b,{p\; 1}} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 14 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 14 & 13 & 13 & 10 & 10 & 0 & 5 & 0 & \}\end{matrix}$

RunningSub2P

Using the value of the first active element in a as a basis, thisinstruction subtracts the amounts in active elements in b from thebasis. Predicate (control vector)p determines which elements participatein the subtraction operation. Inactive elements prior to the firstactive elements are copied into the destination. This instruction storesthe values after being subtracted into the destination register. Asshown below, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that the RunningSub2P instruction uses the destination register asone of its inputs.

Vector RunningSub2P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))       s −= b.v[x];     r.v[x] = s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningSub  2P  (a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 14 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 13 & 13 & 10 & 10 & 5 & 5 & {- 2} & 7 & \}\end{matrix}!}p\; 0};{a = {{RunningSub}\mspace{11mu} 2{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 14 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \} \\\; & {p\; 1} & = & \{ & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 13 & 13 & 10 & 10 & 5 & 0 & {- 2} & 0 & \}\end{matrix}$

RunningShift1R

Using the value of the first active element in a as a basis, thisinstruction right-shifts this basis by the cumulative number of bitsspecified by active elements in b. Predicate p determines which elementsparticipate in the accumulation of shift-counts. Inactive elements priorto the first active elements are copied into the destination. Thisinstruction stores the values prior to being shifted into thedestination register. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction. Note that the RunningShift1Rinstruction uses the destination register as one of its inputs.

Vector RunningShift1R(const Vector &a, const Vector &b, const Vector &p){   Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if(gPred.v[x] && p.v[x])     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if (gPred.v[x] && p.v[x])       s >>= b.v[x];   }  return(r); }

Examples:

 ∼ p 0; a = RunningShift  1R(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 64 & 64 & 64 & 64 & 64 & 64 & 64 & 64 & \} \\\; & b & = & \{ & 0 & 1 & 1 & 2 & 2 & 3 & 3 & 4 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 64 & 64 & 32 & 16 & 16 & 16 & 2 & 64 & \}\end{matrix}!}p\; 0};{a = {{RunningShift}\mspace{11mu} 1{R\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 64 & 64 & 64 & 64 & 64 & 64 & 64 & 64 & \} \\\; & b & = & \{ & 0 & 1 & 1 & 2 & 2 & 3 & 3 & 4 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 64 & 64 & 32 & 16 & 16 & 16 & 2 & 0 & \}\end{matrix}$

RunningShift2R

Using the value of the first active element in a as a basis, thisinstruction right-shifts this basis by the cumulative number of bitsspecified by active elements in b. Predicate p determines which elementsparticipate in the accumulation of shift-counts. Inactive elements priorto the first active elements are copied into the destination. Thisinstruction stores the values after being shifted into the destinationregister. As shown below, in some embodiments, the instruction processesall elements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that the RunningShift2R instruction uses thedestination register as one of its inputs.

Vector RunningShift2R(const Vector &a, const Vector &b, const Vector &p){   Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if(gPred.v[x] && p.v[x])     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if(gPred.v[x] && p.v[x])       s >>= b.v[x];     r.v[x] = s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningShift  2R(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 64 & 64 & 64 & 64 & 64 & 64 & 64 & 64 & \} \\\; & b & = & \{ & 0 & 1 & 1 & 2 & 2 & 3 & 3 & 4 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 64 & 32 & 16 & 16 & 16 & 2 & 0 & 64 & \}\end{matrix}!}p\; 0};{a = {{RunningShift}\mspace{11mu} 2{R\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 64 & 64 & 64 & 64 & 64 & 64 & 64 & 64 & \} \\\; & b & = & \{ & 0 & 1 & 1 & 2 & 2 & 3 & 3 & 4 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 64 & 32 & 16 & 16 & 16 & 2 & 0 & 0 & \}\end{matrix}$

RunningShift1L

Using the value of the first active element in a as a basis, thisinstruction left-shifts this basis by the cumulative number of bitsspecified by active elements in b. Predicate p determines which elementsparticipate in the accumulation of shift-counts. Inactive elements priorto the first active elements are copied into the destination. Thisinstruction stores the values prior to being shifted into thedestination register. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction. Note that the RunningShift1Linstruction uses the destination register as one of its inputs.

Vector RunningShift1L(const Vector &a, const Vector &b, const Vector &p){   Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if(gPred.v[x] && p.v[x])     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if (gPred.v[x] && p.v[x])       s <<= b.v[x];   }  return(r); }

Examples:

 ∼ p 0; a = RunningShift  1L(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\\; & a & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 0 & 1 & 1 & 1 & 2 & 2 & 2 & 3 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 1 & 2 & 4 & 4 & 4 & 16 & 7 & \}\end{matrix}!}p\; 0};{a = {{RunningShift}\mspace{11mu} 1{L\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 0 & 1 & 1 & 1 & 2 & 2 & 2 & 3 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 1 & 2 & 4 & 4 & 4 & 16 & 0 & \}\end{matrix}$

RunningShift2L

Using the value of the first active element in a as a basis, thisinstruction left-shifts this basis by the cumulative number of bitsspecified by active elements in b. Predicate p determines which elementsparticipate in the accumulation of shift-counts. Inactive elements priorto the first active elements are copied into the destination. Thisinstruction stores the values after being shifted into the destinationregister. As shown below, in some embodiments, the instruction processesall elements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that the RunningShift2L instruction uses thedestination register as one of its inputs.

Vector RunningShift2L(const Vector &a, const Vector &b, const Vector &p){   Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if(gPred.v[x] && p.v[x])     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if(gPred.v[x] && p.v[x])       s <<= b.v[x];     r.v[x] = s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningShift  2L(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 0 & 1 & 1 & 1 & 2 & 2 & 2 & 3 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 2 & 4 & 4 & 4 & 16 & 64 & 7 & \}\end{matrix}!}p\; 0};{a = {{RunningShift}\mspace{11mu} 2{L\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {p\; 0} & = & \{ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & \} \\\; & a & = & \{ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & \} \\\; & b & = & \{ & 0 & 1 & 1 & 1 & 2 & 2 & 2 & 3 & \} \\\; & {p\; 1} & = & \{ & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & \} \\{{On}\mspace{14mu} {Exit}\text{:}} & a & = & \{ & 0 & 2 & 4 & 4 & 4 & 16 & 64 & 0 & \}\end{matrix}$

RunningMin1P

Using the value of the first active element in a as a basis, theRunningMin1P instruction calculates the cumulative minima with activeelements in b from this basis. Predicate p determines which elements arecompared in determining the cumulative minima. Inactive elements priorto the first active elements are copied into the destination. Thisinstruction stores the values prior to being compared into thedestination register. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction. Note that RunningMin1P uses thedestination register as one of its inputs.

Vector RunningMin1P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if ((gPred.v[x]) && (p.v[x]))       s = MIN(s,b.v[x]);   }   return(r); }

Examples:

 ∼ p 0; a = RunningMin  1P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}0 & 0 & 1 & 1 & 0 & 1 & 1 & 1\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}0 & 1 & D & C & B & A & 9 & 8\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}2 & 3 & 4 & 5 & 2 & 5 & 3 & 1\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}1 & 0 & 1 & 0 & 0 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}0 & 1 & D & 4 & B & 4 & 4 & 3\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningMin}\mspace{11mu} 1{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}0 & 0 & 1 & 1 & 0 & 1 & 1 & 1\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}0 & 1 & D & C & B & A & 9 & 8\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}2 & 3 & 4 & 5 & 2 & 5 & 3 & 1\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}1 & 0 & 1 & 0 & 0 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}0 & 0 & D & 4 & 0 & 4 & 4 & 3\end{Bmatrix}}\end{matrix}$

RunningMin2P

Using the value of the first active element in a as a basis, theRunningMin2P instruction calculates the cumulative minima with activeelements in b from this basis. Predicate p determines which elements arecompared in determining the cumulative minima. Inactive elements priorto the first active elements are copied into the destination. Thisinstruction stores the values after being compared into the destinationregister. As shown below, in some embodiments, the instruction processesall elements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that RunningMin2P uses the destination registeras one of its inputs.

Vector RunningMin2P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))       s = MIN(s, b.v[x]);     r.v[x] = s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningMin  2P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}0 & 0 & 1 & 1 & 0 & 1 & 1 & 1\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}0 & 1 & D & C & B & A & 9 & 8\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}2 & 3 & 4 & 5 & 2 & 5 & 3 & 1\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}1 & 0 & 1 & 0 & 0 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}0 & 1 & 4 & 4 & B & 4 & 3 & 3\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningMin}\mspace{11mu} 2{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}0 & 0 & 1 & 1 & 0 & 1 & 1 & 1\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}0 & 1 & D & C & B & A & 9 & 8\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}2 & 3 & 4 & 5 & 2 & 5 & 3 & 1\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}1 & 0 & 1 & 0 & 0 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}0 & 0 & 4 & 4 & 0 & 4 & 3 & 3\end{Bmatrix}}\end{matrix}$

RunningMax1P

Using the value of the first active element in a as a basis, theRunningMax1P instruction calculates the cumulative maxima with activeelements in b from this basis. Predicate p determines which elements arecompared in determining the cumulative maxima. Inactive elements priorto the first active elements are copied into the destination. Thisinstruction stores the values prior to being compared into thedestination register. As shown below, in some embodiments, theinstruction processes all elements equivalently; however, predication isperformed by the assignment of the result, and should be considered anintegral part of this instruction. Note that RunningMax1P uses thedestination register as one of its inputs.

Vector RunningMax1P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if ((gPred.v[x]) && (p.v[x]))       s = MAX(s,b.v[x]);   }   return(r); }

Examples:

 ∼ p 0; a = RunningMax  1P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}0 & 0 & 1 & 1 & 0 & 1 & 1 & 1\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}6 & 7 & 2 & 3 & 4 & 5 & 6 & 7\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}8 & 9 & 1 & 4 & 5 & 6 & 7 & 8\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}1 & 0 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}6 & 7 & 2 & 2 & 4 & 2 & 6 & 7\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningMax}\mspace{11mu} 1{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}0 & 0 & 1 & 1 & 0 & 1 & 1 & 1\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}6 & 7 & 2 & 3 & 4 & 5 & 6 & 7\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}8 & 9 & 1 & 4 & 5 & 6 & 7 & 8\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}1 & 0 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}0 & 0 & 2 & 2 & 0 & 2 & 6 & 7\end{Bmatrix}}\end{matrix}$

RunningMax2P

Using the value of the first active element in a as a basis, theRunningMax2P instruction calculates the cumulative maxima with activeelements in b from this basis. Predicate p determines which elements arecompared in determining the cumulative maxima. Inactive elements priorto the first active elements are copied into the destination. Thisinstruction stores the values after being compared into the destinationregister. As shown below, in some embodiments, the instruction processesall elements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that RunningMax2P uses the destination registeras one of its inputs.

Vector RunningMax2P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))       s = MAX(s, b.v[x]);     r.v[x] = s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningMax  2P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}0 & 0 & 1 & 1 & 0 & 1 & 1 & 1\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}6 & 7 & 2 & 3 & 4 & 5 & 6 & 7\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}8 & 9 & 1 & 4 & 5 & 6 & 7 & 8\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}1 & 0 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}6 & 7 & 2 & 2 & 4 & 6 & 7 & 7\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningMax}\mspace{11mu} 2{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}0 & 0 & 1 & 1 & 0 & 1 & 1 & 1\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}6 & 7 & 2 & 3 & 4 & 5 & 6 & 7\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}8 & 9 & 1 & 4 & 5 & 6 & 7 & 8\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}1 & 0 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}0 & 0 & 2 & 2 & 0 & 6 & 7 & 7\end{Bmatrix}}\end{matrix}$

RunningAnd1P

Using the value of the first active element in a as a basis, theRunningAnd1P instruction calculates the cumulative bitwise AND withactive elements in b from this basis. Predicate p determines whichelements participate in the accumulation of addends. Inactive elementsprior to the first active elements are copied into the destination. Thisinstruction stores the values prior to being added into the destinationregister. As shown below, in some embodiments, the instruction processesall elements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that RunningAnd1P uses the destination registeras one of its inputs.

Vector RunningAnd1P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = −1;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if ((gPred.v[x]) && (p.v[x]))       s &= b.v[x];   }  return(r); }

Examples:

 ∼ p 0; a = RunningAnd  1P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 15 & 0 & 1 & 2 & 3 & 4 & 5\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 15 & 7 & 1 & 6 & 1 & 4 & 7\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 15 & 15 & 7 & 7 & 3 & 6 & 5\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningAnd}\; 1{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 15 & 0 & 1 & 2 & 3 & 4 & 5\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 15 & 7 & 1 & 6 & 1 & 4 & 7\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 15 & 15 & 7 & 7 & 0 & 6 & 0\end{Bmatrix}}\end{matrix}$

RunningAnd2P

Using the value of the first active element in a as a basis, thisinstruction calculates the cumulative bitwise AND with active elementsin b from this basis. Predicate p determines which elements participatein the accumulation of addends. Inactive elements prior to the firstactive elements are copied into the destination. This instruction storesthe values after being added into the destination register. As shownbelow, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that RunningAnd2P uses the destination register as one of itsinputs.

Vector RunningAnd2P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = −1;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x]))       s &= b.v[x];     r.v[x] = s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningAnd  2P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 15 & 0 & 1 & 2 & 3 & 4 & 5\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 15 & 7 & 1 & 6 & 1 & 4 & 7\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 15 & 7 & 7 & 6 & 3 & 4 & 5\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningAnd}\; 2{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 15 & 0 & 1 & 2 & 3 & 4 & 5\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 15 & 7 & 1 & 6 & 1 & 4 & 7\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 15 & 7 & 7 & 6 & 0 & 4 & 0\end{Bmatrix}}\end{matrix}$

RunningOr1P

Using the value of the first active element in a as a basis, thisinstruction calculates the cumulative bitwise OR with active elements inb from this basis. Predicate p determines which elements participate inthe accumulation of addends. Inactive elements prior to the first activeelements are copied into the destination. This instruction stores thevalues prior to being added into the destination register. As shownbelow, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that RunningOr1P uses the destination register as one of itsinputs.

Vector RunningOr1P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if ((gPred.v[x]) && (p.v[x] ))       s |= b.v[x];  }   return(r); }

Examples:

 ∼ p 0; a = RunningOr  1P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 1 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 5 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 1 & 3 & 3 & 3 & 9 & 3 & 9\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningOr}\; 1{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 1 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 5 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 1 & 3 & 3 & 3 & 0 & 3 & 0\end{Bmatrix}}\end{matrix}$

RunningOr2P

Using the value of the first active element in a as a basis, thisinstruction calculates the cumulative bitwise OR with active elements inb from this basis. Predicate p determines which elements participate inthe accumulation of addends. Inactive elements prior to the first activeelements are copied into the destination. This instruction stores thevalues after being added into the destination register. As shown below,in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that RunningOr2P uses the destination register as one of itsinputs.

Vector RunningOr2P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))       s |= b.v[x];     r.v[x] = s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningOr  2P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 1 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 5 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 3 & 3 & 3 & 3 & 9 & 7 & 9\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningOr}\; 2{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 1 & 9 & 9 & 9 & 9 & 9 & 9\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 5 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 3 & 3 & 3 & 3 & 0 & 7 & 0\end{Bmatrix}}\end{matrix}$

RunningXor1P

Using the value of the first active element in a as a basis, thisinstruction calculates the cumulative bitwise XOR with active elementsin b from this basis. Predicate p determines which elements participatein the accumulation of addends. Inactive elements prior to the firstactive elements are copied into the destination. This instruction storesthe values prior to being added into the destination register. As shownbelow, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that RunningXor1P uses the destination register as one of itsinputs.

Vector RunningXor1P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if ((gPred.v[x]) && (p.v[x] ))       s {circumflexover ( )}= b.v[x];   }   return(r); }

Examples:

 ∼ p 0; a = RunningXor  1P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 6 & 5 & 4 & 3 & 2 & 1 & 0\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 5 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 6 & 4 & 5 & 5 & 2 & 6 & 0\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningXor}\; 1{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 6 & 5 & 4 & 3 & 2 & 1 & 0\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 5 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 6 & 4 & 5 & 5 & 0 & 6 & 0\end{Bmatrix}}\end{matrix}$

RunningXor2P

Using the value of the first active element in a as a basis, thisinstruction calculates the cumulative bitwise XOR with active elementsin b from this basis. Predicate p determines which elements participatein the accumulation of addends. Inactive elements prior to the firstactive elements are copied into the destination. This instruction storesthe values after being added into the destination register. As shownbelow, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that RunningXor2P uses the destination register as one of itsinputs.

Vector RunningXor2P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 0;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))       s {circumflex over ( )}= b.v[x];    r.v[x] = s;   }   return(r); }

Examples:

 ∼ p 0; a = RunningXor  2P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 6 & 5 & 4 & 3 & 2 & 1 & 0\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 5 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 4 & 5 & 5 & 6 & 2 & 3 & 0\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningXor}\; 2{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 6 & 5 & 4 & 3 & 2 & 1 & 0\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 5 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 4 & 5 & 5 & 6 & 0 & 3 & 0\end{Bmatrix}}\end{matrix}$

RunningMul1P

Using the value of the first active element in a as a basis, thisinstruction calculates the cumulative multiplication with activeelements in b from this basis. Predicate p determines which elementsparticipate in the mulitplication operation. Inactive elements prior tothe first active elements are copied into the destination. Thisinstruction stores the values prior to being added into the destinationregister. As shown below, in some embodiments, the instruction processesall elements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that RunningMul1P uses the destination registeras one of its inputs.

Vector RunningMul1P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 1;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if ((gPred.v[x]) && (p.v[x] ))       s *= b.v[x];  }   return(r); }

Examples:

 ∼ p 0; a = RunningMul  1P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 6 & 5 & 4 & 3 & 2 & 1 & 0\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 2 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 6 & 12 & 12 & 12 & 2 & 36 & 0\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningMul}\; 1{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 6 & 5 & 4 & 3 & 2 & 1 & 0\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 2 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 6 & 12 & 12 & 12 & 0 & 36 & 0\end{Bmatrix}}\end{matrix}$

RunningMul2P

Using the value of the first active element in a as a basis, thisinstruction calculates the cumulative multiplication with activeelements in b from this basis. Predicate p determines which elementsparticipate in the mulitplication operation. Inactive elements prior tothe first active elements are copied into the destination. Thisinstruction stores the values after being added into the destinationregister. As shown below, in some embodiments, the instruction processesall elements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that RunningMul2P uses the destination registeras one of its inputs.

Vector RunningMul2P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 1;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))       s *= b.v[x];     r.v[x] = s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningMul  2P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 6 & 5 & 4 & 3 & 2 & 1 & 0\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 2 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 12 & 12 & 12 & 36 & 2 & 72 & 0\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningMul}\; 2{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}7 & 6 & 5 & 4 & 3 & 2 & 1 & 0\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}7 & 2 & 1 & 2 & 3 & 4 & 2 & 6\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}7 & 12 & 12 & 12 & 36 & 0 & 72 & 0\end{Bmatrix}}\end{matrix}$

RunningDiv1P

Using the value of the first active element in a as a basis, thisinstruction calculates a result of dividing the basis by active elementsin b. Specifically, the basis is divided by a value in a first activeelement and the output of the division is then again divided by a secondactive element and so forth until the basis has been divided by theactive elements in b (note, however, that there can be as few as zeroactive elements). Predicate p determines which elements participate inthe division operation. Inactive elements prior to the first activeelements are copied into the destination. This instruction stores thevalues prior to being divided into the destination register. As shownbelow, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that RunningDiv1P uses the destination register as one of itsinputs.

Vector RunningDiv1P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 1;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {    r.v[x] = s;     if ((gPred.v[x]) && (p.v[x] ))       s /= b.v[x];  }   return(r); }

Examples:

 ∼ p 0; a = RunningDiv 1P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}12 & 64 & 5 & 4 & 3 & 9 & 1 & 7\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}2 & 2 & 4 & 2 & 2 & 2 & 2 & 2\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}12 & 64 & 32 & 8 & 8 & 9 & 4 & 7\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningDiv}\; 1{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}12 & 64 & 5 & 4 & 3 & 9 & 1 & 0\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}2 & 2 & 4 & 2 & 2 & 2 & 2 & 2\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}12 & 64 & 32 & 8 & 8 & 0 & 4 & 0\end{Bmatrix}}\end{matrix}$

RunningDiv2P

Using the value of the first active element in a as a basis, thisinstruction calculates a result of dividing the basis by active elementsin b. Specifically, the basis is divided by a value in a first activeelement and the output of the division is then again divided by a secondactive element and so forth until the basis has been divided by theactive elements in b (note, however, that there can be as few as zeroactive elements). Predicate p determines which elements participate inthe division operation. Inactive elements prior to the first activeelements are copied into the destination. This instruction stores thevalues after to being divided into the destination register. As shownbelow, in some embodiments, the instruction processes all elementsequivalently; however, predication is performed by the assignment of theresult, and should be considered an integral part of this instruction.Note that RunningDiv2P uses the destination register as one of itsinputs.

Vector RunningDiv2P(const Vector &a, const Vector &b, const Vector &p) {  Vector r;   int s, x;   s = 1;   for (x=0; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))     {       s = a.v[x];       break;     }    else       r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if((gPred.v[x]) && (p.v[x] ))       s /= b.v[x];     r.v[x] = s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningDiv 2P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}12 & 64 & 5 & 4 & 3 & 9 & 1 & 7\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}2 & 2 & 4 & 2 & 2 & 2 & 2 & 2\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}12 & 32 & 8 & 8 & 4 & 9 & 2 & 7\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningDiv}\; 2{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}12 & 64 & 5 & 4 & 3 & 9 & 1 & 7\end{Bmatrix}} \\\; & {b = \begin{Bmatrix}2 & 2 & 4 & 2 & 2 & 2 & 2 & 2\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \begin{Bmatrix}12 & 32 & 8 & 8 & 4 & 0 & 2 & 0\end{Bmatrix}}\end{matrix}$

RunningInv1P

The RunningInv1P instruction can be used to implement an efficientcumulative inversion operation by using a running inversion to computeoutputs for active elements of a result vector.

When executed, the RunningInv1P instruction acquires a base value from akey element position in an input vector, where the key element positionis a first/leftmost relevant element in the input vector. In thedescribed embodiments, a relevant element is an element for which acorresponding element of a first predicate vector and a second predicatevector are active, e.g., contain a non-zero value. In these embodiments,the first predicate vector can be a global predicate vector (e.g.,gPred) and the second predicate vector can be a control vector (i.e., alocal predicate vector).

The RunningInv1P instruction then generates a result vector by, for eachactive element of the result vector to the right of the key elementposition, writing to the element in the result vector a value equal tothe result of performing a bitwise inversion operation on the base valuea number of times equal to the number of relevant elements from the keyelement position to and including the element to the left of the elementin the result vector.

The RunningInv1P instruction also copies the base value to the keyelement position of the result vector. Additionally, for active elementsof the result vector to the left of the key element position, theRunningInv1P instruction copies a value from a corresponding element ofthe input vector to the element of the result vector.

As shown below, in some embodiments, the instruction processes allelements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that the RunningInv1P instruction uses thedestination register as one of its inputs.

Vector RunningInv1P (const Vector &a, const Vector &p) {   Vector r;  int x;   scalar s;   for (x=0; x<VECLEN; ++x)   {     if (gPred.v[x]&& p.v[x])     {       s = a.v[x];       break;     }     else if(gp.v[x]) r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if(gp.v[x]) r.v[x] = s;     if (gp.v[x] && p.v[x]) s = ~s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningInv 1P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & 99\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \begin{Bmatrix}12 & 32 & {- 33} & 32 & 32 & 19 & {- 33} & 99\end{Bmatrix}}\end{matrix}!}{p\; 0}};{a = {{RunningInv}\; 1{P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \begin{Bmatrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\\; & {{p\; 1} = \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\\; & {a = \begin{Bmatrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & 99\end{Bmatrix}} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \begin{Bmatrix}12 & 32 & {- 33} & 32 & 32 & 0 & {- 33} & 0\end{Bmatrix}}\end{matrix}$

RunningInv2P

The RunningInv2P instruction can be used to implement an efficientcumulative inversion operation by using a running inversion to computeoutputs for active elements of a result vector.

When executed, the RunningInv2P instruction acquires a base value from akey element position in an input vector, where the key element positionis a first/leftmost relevant element in the input vector. In thedescribed embodiments, a relevant element is an element for which acorresponding element of a first predicate vector and a second predicatevector are active, e.g., contain a non-zero value. In these embodiments,the first predicate vector can be a global predicate vector (e.g.,gPred) and the second predicate vector can be a control vector (i.e., alocal predicate vector).

The RunningInv2P instruction then generates a result vector by, for eachactive element of the result vector to the right of the key elementposition, writing to the element in the result vector a value equal tothe result of performing a bitwise inversion operation on the base valuea number of times equal to the number of relevant elements from the keyelement position to and including the element in the result vector.

The RunningInv2P instruction can also set the key element position inthe result vector a value equal to a result of performing the bitwiseinversion operation on the base value once.

Additionally, for active elements of the result vector to the left ofthe key element position, the RunningInv2P instruction copies a valuefrom a corresponding element of the input vector to the element of theresult vector.

As shown below, in some embodiments, the instruction processes allelements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that the RunningInv2P instruction uses thedestination register as one of its inputs.

Vector RunningInv2P (const Vector &a, const Vector &p) {   Vector r;  int x;   scalar s;   for (x=0; x<VECLEN; ++x)   {     if (gPred.v[x]&& p.v[x])     {       s = a.v[x];       break;     }     else if(gp.v[x]) r.v[x] = a.v[x];   }   for (x<VECLEN; ++x)   {     if (gp.v[x]&& p.v[x]) s = ~s;     if (gp.v[x]) r.v[x] = s;   }   return(r); }

Examples:

 ∼ p 0; a = RunningInv 2 P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {{p\; 1} = \left\{ \begin{matrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \left\{ \begin{matrix}12 & {- 33} & 32 & 32 & {- 33} & 19 & 32 & \left. 99 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {{RunningInv}\; 2\; {P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {{p\; 1} = \left\{ \begin{matrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \left\{ \begin{matrix}12 & {- 33} & 32 & 32 & {- 33} & 0 & 32 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

RunningNeg1P

The RunningNeg1P instruction can be used to implement an efficientcumulative negation operation by using a running bitwise negation tocompute outputs for active elements of a result vector.

When executed, the RunningNeg1P instruction acquires a base value from akey element position in an input vector, where the key element positionis a first/leftmost relevant element in the input vector. In thedescribed embodiments, a relevant element is an element for which acorresponding element of a first predicate vector and a second predicatevector are active, e.g., contain a non-zero value. In these embodiments,the first predicate vector can be a global predicate vector (e.g.,gPred) and the second predicate vector can be a control vector (i.e., alocal predicate vector).

The RunningNeg1P instruction then generates a result vector by, for eachactive element of the result vector to the right of the key elementposition, writing to the element in the result vector a value equal tothe result of performing a negation operation on the base value a numberof times equal to the number of relevant elements from the key elementposition to and including the element to the left of the element in theresult vector.

The RunningNeg1P instruction also copies the base value to the keyelement position of the result vector. Additionally, for active elementsof the result vector to the left of the key element position, theRunningNeg1P instruction copies a value from a corresponding element ofthe input vector to the element of the result vector.

As shown below, in some embodiments, the instruction processes allelements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that the RunningNeg1P instruction uses thedestination register as one of its inputs.

Vector RunningNeg1P (const Vector &a, const Vector &p) {   Vector r;  int x;   scalar s;   for (x=0; x<VECLEN; ++x)   {     if (gPred.v[x]&& p.v[x])     {       s = a.v[x];       break;     }     else if(gp.v[x]) r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if(gp.v[x]) r.v[x] = s;     if (gp.v[x] && p.v[x]) s = −s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningNeg 1 P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {{p\; 1} = \left\{ \begin{matrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \left\{ \begin{matrix}12 & 32 & {- 32} & 32 & 32 & 19 & {- 32} & \left. 99 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {{RunningNeg}\; 1\; {P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {{p\; 1} = \left\{ \begin{matrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \left\{ \begin{matrix}12 & 32 & {- 32} & 32 & 32 & 0 & {- 32} & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

RunningNeg2P

The RunningNeg2P instruction can be used to implement an efficientcumulative negation operation by using a running bitwise negation tocompute outputs for active elements of a result vector.

When executed, the RunningNeg2P instruction acquires a base value from akey element position in an input vector, where the key element positionis a first/leftmost relevant element in the input vector. In thedescribed embodiments, a relevant element is an element for which acorresponding element of a first predicate vector and a second predicatevector are active, e.g., contain a non-zero value. In these embodiments,the first predicate vector can be a global predicate vector (e.g.,gPred) and the second predicate vector can be a control vector (i.e., alocal predicate vector).

The RunningNeg2P instruction then generates a result vector by, for eachactive element of the result vector to the right of the key elementposition, writing to the element in the result vector a value equal tothe result of performing a bitwise negation operation on the base valuea number of times equal to the number of relevant elements from the keyelement position to and including the element in the result vector.

The RunningNeg2P instruction can also set the key element position inthe result vector a value equal to a result of performing the negationoperation on the base value once.

Additionally, for active elements of the result vector to the left ofthe key element position, the RunningNeg2P instruction copies a valuefrom a corresponding element of the input vector to the element of theresult vector.

As shown below, in some embodiments, the instruction processes allelements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that the RunningNeg2P instruction uses thedestination register as one of its inputs.

Vector RunningNeg2P (const Vector &a, const Vector &p) {   Vector r;  int x;   scalar s;   for (x=0; x<VECLEN; ++x)   {     if (gPred.v[x]&& p.v[x])     {       s = a.v[x];       break;     }     else if(gp.v[x]) r.v[x] = a.v[x];   }   for (x<VECLEN; ++x)   {     if (gp.v[x]&& p.v[x]) s = −s;     if (gp.v[x]) r.v[x] = s;   }   return(r); }

Examples:

 ∼ p 0; a = RunningNeg 2 P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {{p\; 1} = \left\{ \begin{matrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \left\{ \begin{matrix}12 & {- 32} & 32 & 32 & {- 32} & 19 & 32 & \left. 99 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {{RunningNeg}\; 2\; {P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {{p\; 1} = \left\{ \begin{matrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \left\{ \begin{matrix}12 & {- 32} & 32 & 32 & {- 32} & 0 & 32 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

RunningNot1P

The RunningNot1P instruction can be used to implement an efficientcumulative logical NOT operation by using a running logical NOT tocompute outputs for active elements of a result vector.

When executed, the RunningNot1P instruction acquires a base value from akey element position in an input vector, where the key element positionis a first/leftmost relevant element in the input vector. In thedescribed embodiments, a relevant element is an element for which acorresponding element of a first predicate vector and a second predicatevector are active, e.g., contain a non-zero value. In these embodiments,the first predicate vector can be a global predicate vector (e.g.,gPred) and the second predicate vector can be a control vector (i.e., alocal predicate vector).

The RunningNot1P instruction then generates a result vector by, for eachactive element of the result vector to the right of the key elementposition, writing to the element in the result vector a value equal tothe result of performing a logical NOT operation on the base value anumber of times equal to the number of relevant elements from the keyelement position to and including the element to the left of the elementin the result vector.

The RunningNot1P instruction also copies the base value to the keyelement position of the result vector. Additionally, for active elementsof the result vector to the left of the key element position, theRunningNot1P instruction copies a value from a corresponding element ofthe input vector to the element of the result vector.

As shown below, in some embodiments, the instruction processes allelements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that the RunningNot1P instruction uses thedestination register as one of its inputs.

Vector RunningNot1P (const Vector &a, const Vector &p) {   Vector r;  int x;   scalar s;   for (x=0; x<VECLEN; ++x)   {     if (gPred.v[x]&& p.v[x])     {       s = a.v[x];       break;     }     else if(gp.v[x]) r.v[x] = a.v[x];   }   for (; x<VECLEN; ++x)   {     if(gp.v[x]) r.v[x] = s;     if (gp.v[x] && p.v[x]) s = !s;   }  return(r); }

Examples:

 ∼ p 0; a = RunningNot 1 P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {{p\; 1} = \left\{ \begin{matrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \left\{ \begin{matrix}12 & 32 & 0 & 1 & 1 & 19 & 0 & \left. 99 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {{RunningNot}\; 1\; {P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {{p\; 1} = \left\{ \begin{matrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \left\{ \begin{matrix}12 & 32 & 0 & 1 & 1 & 0 & 0 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

RunningNot2P

The RunningNot2P instruction can be used to implement an efficientcumulative logical NOT operation by using a running logical NOT tocompute outputs for active elements of a result vector.

When executed, the RunningNot2P instruction acquires a base value from akey element position in an input vector, where the key element positionis a first/leftmost relevant element in the input vector. In thedescribed embodiments, a relevant element is an element for which acorresponding element of a first predicate vector and a second predicatevector are active, e.g., contain a non-zero value. In these embodiments,the first predicate vector can be a global predicate vector (e.g.,gPred) and the second predicate vector can be a control vector (i.e., alocal predicate vector).

The RunningNot2P instruction then generates a result vector by, for eachactive element of the result vector to the right of the key elementposition, writing to the element in the result vector a value equal tothe result of performing a bitwise negation operation on the base valuea number of times equal to the number of relevant elements from the keyelement position to and including the element in the result vector.

The RunningNot2P instruction can also set the key element position inthe result vector a value equal to a result of performing the logicalNOT operation on the base value once.

Additionally, for active elements of the result vector to the left ofthe key element position, the RunningNot2P instruction copies a valuefrom a corresponding element of the input vector to the element of theresult vector.

As shown below, in some embodiments, the instruction processes allelements equivalently; however, predication is performed by theassignment of the result, and should be considered an integral part ofthis instruction. Note that the RunningNot2P instruction uses thedestination register as one of its inputs.

Vector RunningNot2P (const Vector &a, const Vector &p) {   Vector r;  int x;   scalar s;   for (x=0; x<VECLEN; ++x)   {     if (gPred.v[x]&& p.v[x])     {       s = a.v[x];       break;     }     else if(gp.v[x]) r.v[x] = a.v[x];   }   for (x<VECLEN; ++x)   {     if (gp.v[x]&& p.v[x]) s = !s;     if (gp.v[x]) r.v[x] = s;   }   return(r); }

Examples:

 ∼ p 0; a = RunningNot 2 P(a, b, p 1); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {{p\; 1} = \left\{ \begin{matrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \left\{ \begin{matrix}12 & 0 & 1 & 1 & 0 & 19 & 1 & \left. 99 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {{RunningNot}\; 2\; {P\left( {a,b,{p\; 1}} \right)}}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {{p\; 1} = \left\{ \begin{matrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {r = \left\{ \begin{matrix}12 & 0 & 1 & 1 & 0 & 0 & 1 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

Vector Read/Write Instructions

The following section describes instructions for performing memoryoperations in accordance with the described embodiments. For clarity,these example instructions are described using a single data type and asingle addressing mode. Thus, the described instructions provide a basicunderstanding of the read/write operations used in the describedembodiments. In some embodiments, these instructions are extended tosupport different data types, addressing modes, etc. Some embodimentsprovide support for a virtual memory system in these instructions.

VectorRead

This instruction reads a vector of data from a vector of addressescalculated from the instruction's inputs. A vector of offsets in offsetare scaled by 1, 2, 4, or 8 according to type, and added to the scalaraddress specified in ptr. Data is returned in the destination register,and either sign-extended or zero-padded depending on whether signed orunsigned data is loaded. If this instruction is predicated, onlyaddresses corresponding to active elements are read. This instructionfaults on any attempt to read an unmapped page. Depending on the settingof the STM bit, the operating system may choose to set bits in the FSRin response to illegal memory operations in other than the first activeelement. The syntax for this instruction is:

Vector VectorRead<type>(void *ptr, Vector offset);

VectorReadFF

This instruction reads a vector of data from a vector of addressescalculated from its inputs. Only the first active element can generate amemory fault or exception. A vector of offsets in offset are scaled by1, 2, 4, or 8, according to type, and added to the scalar addressspecified in ptr. Data is returned in the destination register. If thisinstruction is predicated, only addresses corresponding to activeelements are read.

This instruction only takes a page fault if the first active address isillegal or otherwise unmapped. If a faulting condition occurs inpositions subsequent to the first active element, no exception isgenerated and corresponding bits in the FSR are set. This allowssubsequent elements to avoid paging-in data from mass storage when thedata is not certain to be used.

The interface for this instruction is:

Vector VectorRead<type>FF(void *ptr, Vector offset);

VectorReadNF

This instruction reads a vector of data from a vector of addressescalculated from its inputs. This instruction does not generate anymemory faults, and thus may not actually read memory if a fault shouldhave occurred. A vector of offsets in offset are scaled by 1, 2, 4, or8, according to type, and added to the scalar address specified in ptr.Data is returned in the destination register. If this instruction ispredicated, only addresses corresponding to active elements are read.

This instruction does not fault if an address is illegal or otherwiseunmapped. If a faulting condition occurs, no exception is generated andcorresponding bits in the FSR are set. This provides a mechanism forsoftware speculation to avoid paging-in data from mass storage when thedata is not certain to be used. This instruction is useful whenspeculatively pointer chasing, and to prefetch data that may not beaccessed.

The interface for this instruction is:

-   -   Vector VectorRead<type>NF(void *ptr, Vector offset);    -   Flags: NONE: Set if no elements read; cleared otherwise.

VectorWriteInt

This instruction writes a vector of data in values to a vector ofaddresses calculated from the instruction's inputs. A vector of offsetsin offset are scaled by 1, 2, 4, or 8, and added to the scalar addressspecified in ptr. If this instruction is predicated, only addressescorresponding to active elements are written. Write addresses should bevalid, and there is no avoidance of program termination in the event ofa write to an illegal or protected address. The syntax for thisinstruction is:

-   -   Vector VectorWriteInt(void *ptr, Vector offset, Vector values);

Sequential Vector Reads and Writes

Although the embodiments described above primarily operate on memoryusing a gather/scatter model, alternative embodiments include a set ofsequential memory read/write instructions to handle the case wherememory is addressed sequentially. In these embodiments, these memoryoperations: (1) support predication and zeroing; (2) work on naturallyaligned boundaries for any data type; and (3) support normal andfirst-faulting variants (to support software speculation).

VectorLEA

This instruction calculates a vector of addresses from its inputs. Avector of offsets in offset are scaled by 1, 2, 4, or 8, and added tothe scalar address specified in ptr. The syntax for this instruction is:

Vector VectorLEA(void *ptr, Vector offset);

VectorIndex

This instruction populates a vector by monotonically increasing a by bfor each vector position. The given value of a is stored in the firstelement of the destination, and b is added to every position thereafter.While the example below processes all elements, predication is performedby the assignment of the result, and should be considered an integralpart of this instruction. The syntax for this instruction

Vector Vectorindex(int a, int b)

This instruction operates as follows:

Vector VectorIndex(int a, int b) {   Vector r = 0;   int x;   for (x=0;x<VECLEN; ++x)     r.v[x] = a + b * x;   return(r); }

Examples:

 ∼ p 0; a = VectorIndex(1, 2); ${{\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}0 & 1 & 1 & 1 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}9 & 3 & 5 & 7 & 9 & 11 & 13 & \left. 9 \right\}\end{matrix} \right.}\end{matrix}!}p\; 0};{a = {{VectorIndex}\left( {1,2} \right)}};$$\begin{matrix}{{On}\mspace{14mu} {Entry}\text{:}} & {{p\; 0} = \left\{ \begin{matrix}1 & 1 & 1 & 1 & 1 & 1 & 1 & \left. 0 \right\}\end{matrix} \right.} \\\; & {a = \left\{ \begin{matrix}9 & 9 & 9 & 9 & 9 & 9 & 9 & \left. 9 \right\}\end{matrix} \right.} \\{{On}\mspace{14mu} {Exit}\text{:}} & {a = \left\{ \begin{matrix}0 & 3 & 5 & 7 & 9 & 11 & 13 & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

Executing Program Code

FIG. 20 presents a flowchart illustrating a process for executingprogram code in accordance with the described embodiments. As can beseen in FIG. 20, when executing program code, processor 102 receives afirst input vector, a second input vector, a control vector, andpossibly a predicate vector that include N elements (step 2000). Next,using the vectors, processor 102 generates a result vector (step 2002).

In the following examples, we describe “possibly” receiving a predicatevector. Although the described embodiments can use a predicate vectorwhen generating the result vector, these embodiments do not need toreceive a predicate vector in order to generate the result vector (i.e.,the predicate vector is optional). In these embodiments, if no predicatevector is received, processor 102 assumes a predicate vector for whicheach element contains a non-zero value.

In some embodiments, when generating the result vector, processor 102performs some or all of a set of operations for generating the resultvector in parallel (e.g., using vector execution unit 204). Hence, inthese embodiments, the values to be written to the result vector can bedetermined in parallel for all the elements of the result vector andwritten to the elements of the result vector in parallel. However, inalternative embodiments, one or more of the operations for generatingthe result vector can be performed in series with other operations forgenerating the result vector.

In the following examples, we use zero and non-zero values to describethe configuration of vectors and the performance of operations, however,in different embodiments, other values can be used. In addition,although we refer embodiments that use “left” and “right” directions todetermine elements in vectors when performing operations, in alternativeembodiments, the directions could be reversed.

In the following examples, we describe “relevant” elements. In thedescribed embodiments, if the predicate vector is received, a relevantelement in the result vector is an element in the result vector forwhich the corresponding element in the predicate vector and thecorresponding element in the control vector contain non-zero values.Otherwise, a relevant element in the result vector is an element in theresult vector for which the corresponding element in the control vectorcontains a non-zero value.

In the following description, we refer to numerical values in decimalform, such as 8, −32, etc. However, in the described embodiments,processor 102 can process these values in binary form. For example, thevalue of −32 can be represented in binary as follows “b11100000.”

RunningInv1P

FIGS. 21A-21B (collectively, “FIG. 21”) present a flowchart illustratinga process for generating a result vector in accordance with thedescribed embodiments. More specifically, the flowchart in FIG. 21 showsoperations performed for embodiments of the RunningInv1P instruction. Insome embodiments, the RunningInv1P instruction can be used to perform anefficient running inversion using a cumulative inversion operation.

In the described embodiments, the operations shown in FIG. 21 areperformed as part of step 2002 in FIG. 20. Thus, for the purposes ofdescribing the operations shown in FIG. 21, we assume that the inputvector, the control vector, and possibly a predicate vector have beenreceived, as shown in step 2000 in FIG. 20. Additionally, in thefollowing description, the embodiments are described using non-zerovalues, which represent active elements. However, alternativeembodiments are not limited to using non-zero values; any value can beused (zero, positive numbers, chars, TRUE/FALSE, etc.).

Recall that, in the described embodiments, the predicate vector isoptional and hence may not be received. If a predicate vector is notreceived, processor 102 assumes a predicate vector where each elementcontains a non-zero value (and, more generally, an active value) andperforms the operations in FIG. 21 accordingly. In other words, thepredicate vector described below (e.g., with respect to step 2104, etc.)can be an assumed predicate vector.

As shown in FIG. 21, processor 102 first captures a base value containedin an element of the input vector at a key element position (step 2100).In the described embodiments, the key element position is theleftmost/first relevant element in the input vector.

Next, for each of the elements of the result vector in parallel (step2102), processor 102 determines if a corresponding element of thepredicate vector contains a non-zero value (step 2104). If not,processor 102 either leaves unchanged the element in the result vectoror writes a zero in the element of the result vector (step 2106). Forexample, assuming that the input vector (iv1), cv, and pred contain thevalues shown, the result vector (res) could be generated as follows forzeroing:

$\begin{matrix}{{iv}\; 1} & {= \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{pred} & {= \begin{Bmatrix}0 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\{cv} & {= \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{res} & {= \left\{ \begin{matrix}0 & X & X & X & X & 0 & X & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

In some embodiments, the result vector can include one or more elementsthat contain initial values that were computed during an earlieroperation. Alternatively, the result vector can include one or moreelements that contain initial values that were copied to the resultvector from another vector during the generation of the result vector.The initial values in these elements are the values that are leftunchanged according to predication.

Note that, although we show the inversion and the predication/zeroingoperations together in FIG. 21, these operations can occur in separatelyin some embodiments. More specifically, in some embodiments, theoperations shown in steps 2108-2118 in FIG. 21 can be performed in one(parallel) operation to generate a result vector with values forelements in the same locations as elements where predicate vectorcontains a non-zero value. A separate operation can then be performed tocopy the result vector to a destination, with the predication/zeroingshown in steps 2104-2106 being performed during the copy operation. Inthe following description, for clarity and brevity, we describeembodiments where the inversion and the predication take place in asingle (parallel) operation.

Processor 102 then determines if the element in the result vector is ata key element position in the result vector (step 2108). If so,processor 102 sets the element in the result vector equal to the basevalue (step 2110). For example, assuming iv1, cv, and pred contain thevalues shown, res could be generated as follows:

$\begin{matrix}{{iv}\; 1} & {= \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{pred} & {= \begin{Bmatrix}0 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\{cv} & {= \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{res} & {= \left\{ \begin{matrix}X & 32 & X & X & X & X & X & \left. X \right\}\end{matrix} \right.}\end{matrix}$

As this example shows, the value of 32 from the key element position ofthe iv1 is written to the key element position of res. For clarity,other elements in res are marked with an X.

Note that a key element position may not exist (i.e., there may be noelement position where both pred[x] and cv[x] contain non-zero values).In such a case, each element in the result vector is set equal to thecorresponding element in the input vector, as is described below withrespect to step 2114.

If the element in the result vector is not at the key element position,processor 102 determines if the element in the result vector is locatedto the left of the key element position in the result vector (step2112). If so, processor 102 sets the element in the result vector equalto a corresponding element in iv1 (step 2114). For example, assumingiv1, cv, and pred contain the values shown, res could be generated asfollows:

$\begin{matrix}{{iv}\; 1} & {= \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{pred} & {= \begin{Bmatrix}0 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\{cv} & {= \begin{Bmatrix}0 & 0 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{res} & {= \left\{ \begin{matrix}X & 32 & X & X & X & X & X & \left. X \right\}\end{matrix} \right.}\end{matrix}$

This example shows elements to the left of the key element position forwhich a value from an element iv1[x] has been copied to thecorresponding element of res[x]. For clarity, other elements in res aremarked with an X. As described above, a key element position need notexist in the result vector. In other words, there may be no elementposition in both the predicate vector and the control vector where boththe vectors contain a non-zero value or an active value. (Alternatively,in embodiments where pred[x] is not received, there may be no elementposition where cv[x] contains a non-zero value or an active value.) Ifthis case occurs, the values from iv1 are simply copied to each elementin res where the corresponding element in pred contains a non-zero valueor an active value.

If the element in the result vector is located to the right of the keyelement position (step 2112), processor 102 determines a number ofrelevant elements from the key element position to and including theelement to the left of the element in the result vector (step 2116).Then, processor 102 sets the element in the result vector equal to aresult of performing the inversion operation on the base value a numberof times equal to the number of relevant elements (step 2118).

For example, assuming iv1, cv, and pred contain the values shown, rescould be generated as follows (for clarity, elements that are notwritten to during this operation are marked with an X in res.):

$\begin{matrix}{{iv}\; 1} & {= \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{pred} & {= \begin{Bmatrix}0 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\{cv} & {= \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{res} & {= \left\{ \begin{matrix}X & 32 & {- 33} & 32 & 32 & X & {- 33} & \left. X \right\}\end{matrix} \right.}\end{matrix}$

As this example shows, the key element position is the second elementposition, and the base value is 32 (which is written to the key elementposition of res as described above with respect to steps 2108-2110).Thus, the elements to the right of the key element position in res startat the third element of res. For the third element in res, processor 102determines the number of relevant elements from the key element positionto and including the element to the left of the element in the resultvector (i.e., the third element of the input vector). In this case, thenumber of relevant elements is 1, as the key element position is theonly element position to the left of the third element in the inputvector. Processor 102 then computes a single inversion of the base value32=−33, and writes −33 into the third element of res.

For the fourth element of res, processor 102 determines the number ofrelevant elements is 2, as the key element position and the thirdelement position are to the left of the fourth element in the resultvector. Processor 102 then computes a result of inverting the base valuetwice inv(inv(32))=32, and writes 32 into the fourth element of res.

For the fifth element of res, processor 102 determines the number ofrelevant elements is 2, as the key element position, the third elementposition and the fourth element are to the left of the fifth element inthe result vector (and the fourth element does not contribute to therunning unary operation because pred and cv are not both non-zero).Processor 102 then computes a result of inverting the base value twiceinv(inv(32))=32, and writes 32 into the fifth element of res.

For the sixth element of res, processor 102 determines that this elementis inactive. Since this element, and the eighth element, are not set inthis operation, an X is shown in res.

For the seventh element of res, processor 102 determines the number ofrelevant elements is 3. Processor 102 then computes a result ofinverting the base value three times inv(inv(inv(32)))=−33, and writes−33 into the seventh element of res.

As described above, the RunningInv1P instruction can be used toimplement an efficient running inversion operation, and hence can beused for performing one or more of a vectorized operations or avectorized formula.

RunningInv2P

FIGS. 22A-22B (collectively, “FIG. 22”) present a flowchart illustratinga process for generating a result vector in accordance with thedescribed embodiments. More specifically, the flowchart in FIG. 22 showsoperations performed for embodiments of the RunningInv2P instruction. Insome embodiments, the RunningInv2P instruction can be used to perform anefficient running inversion using a cumulative inversion operation.

In the described embodiments, the operations shown in FIG. 22 areperformed as part of step 2002 in FIG. 20. Thus, for the purposes ofdescribing the operations shown in FIG. 22, we assume that the inputvector, the control vector, and possibly a predicate vector have beenreceived, as shown in step 2000 in FIG. 20. Additionally, in thefollowing description, the embodiments are described using non-zerovalues, which represent active elements. However, alternativeembodiments are not limited to using non-zero values; any value can beused (zero, positive numbers, chars, TRUE/FALSE, etc.).

Recall that, in the described embodiments, the predicate vector isoptional and hence may not be received. If a predicate vector is notreceived, processor 102 assumes a predicate vector where each elementcontains a non-zero value (and, more generally, an active value) andperforms the operations in FIG. 22 accordingly. In other words, thepredicate vector described below (e.g., with respect to step 2204, etc.)can be an assumed predicate vector.

As shown in FIG. 22, processor 102 first captures a base value containedin an element of the input vector at a key element position (step 2200).In the described embodiments, the key element position is theleftmost/first relevant element in the first input vector.

Next, for each of the elements of the result vector in parallel (step2202), processor 102 determines if a corresponding element of thepredicate vector contains a non-zero value (step 2204). If not,processor 102 either leaves unchanged the element in the result vectoror writes a zero in the element of the result vector (step 2206). Forexample, assuming that the first input vector (iv1), cv, and predcontain the values shown, the result vector (res) could be generated asfollows for zeroing:

$\begin{matrix}{{iv}\; 1} & {= \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{pred} & {= \begin{Bmatrix}0 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\{cv} & {= \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{res} & {= \left\{ \begin{matrix}0 & X & X & X & X & 0 & X & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

In some embodiments, the result vector can include one or more elementsthat contain initial values that were computed during an earlieroperation. Alternatively, the result vector can include one or moreelements that contain initial values that were copied to the resultvector from another vector during the generation of the result vector.The initial values in these elements are the values that are leftunchanged according to predication.

Note that, although we show the inversion and the predication/zeroingoperations together in FIG. 22, these operations can occur in separatelyin some embodiments. More specifically, in some embodiments, theoperations shown in steps 2208-2218 in FIG. 22 can be performed in one(parallel) operation to generate a result vector with values forelements in the same locations as elements where predicate vectorcontains a non-zero value. A separate operation can then be performed tocopy the result vector to a destination, with the predication/zeroingshown in steps 2204-2206 being performed during the copy operation. Inthe following description, for clarity and brevity, we describeembodiments where the division and the predication take place in asingle (parallel) operation.

Processor 102 then determines if the element in the result vector is ata key element position in the result vector (step 2208). If so,processor 102 determines the inverse of the base value once and storesthe resulting value at the key element position in the result vector(step 2210). For example, assuming ivl, cv, and pred contain the valuesshown, res could be generated as follows:

$\begin{matrix}{{iv}\; 1} & {= \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{pred} & {= \begin{Bmatrix}0 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\{cv} & {= \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{res} & {= \left\{ \begin{matrix}X & {- 33} & X & X & X & X & X & \left. X \right\}\end{matrix} \right.}\end{matrix}$

For this example, processor 102 first determines a value in the keyelement position in the input vector (i.e., the second element of theinput vector), which is 32. Processor 102 then determines the inverse of32=−33, and writes −33 into the second element of res. For clarity,other elements in res are marked with an X.

Note that a key element position may not exist (i.e., there may be noelement position where both pred[x] and cv[x] contain non-zero values).In such a case, each element in the result vector is set equal to thecorresponding element in the input vector, as is described below withrespect to step 2214.

If the element in the result vector is not at the key element position,processor 102 determines if the element in the result vector is locatedto the left of the key element position in the result vector (step2212). If so, processor 102 sets the element in the result vector equalto a corresponding element in iv1 (step 2214). For example, assumingiv1, cv, and pred contain the values shown, res could be generated asfollows:

$\begin{matrix}{{iv}\; 1} & {= \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{pred} & {= \begin{Bmatrix}0 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\{cv} & {= \begin{Bmatrix}0 & 0 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{res} & {= \left\{ \begin{matrix}X & 32 & X & X & X & X & X & \left. X \right\}\end{matrix} \right.}\end{matrix}$

This example shows elements to the left of the key element position forwhich a value from an element iv1[x] has been copied to thecorresponding element of res[x]. For clarity, other elements in res aremarked with an X. As described above, a key element position need notexist in the result vector. In other words, there may be no elementposition in both the predicate vector and the control vector where boththe vectors contain a non-zero value or an active value. (Alternatively,in embodiments where pred[x] is not received, there may be no elementposition where cv[x] contains a non-zero value or an active value.) Ifthis case occurs, the values from iv1 are simply copied to each elementin res where the corresponding element in pred contains a non-zero valueor an active value.

If the element in the result vector is located to the right of the keyelement position (step 2216), processor 102 determines a number ofrelevant elements from the key element position to and including theelement in the result vector (step 2216). Then, processor 102 sets theelement in the result vector equal to a result of performing theinversion operation on the base value a number of times equal to thenumber of relevant elements (step 2218).

For example, assuming iv1, cv, and pred contain the values shown, rescould be generated as follows (for clarity, elements that are notwritten to during this operation are marked with an X in res.):

$\begin{matrix}{{iv}\; 1} & {= \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{pred} & {= \begin{Bmatrix}0 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\{cv} & {= \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{res} & {= \left\{ \begin{matrix}X & {- 33} & 32 & 32 & {- 33} & X & 32 & \left. X \right\}\end{matrix} \right.}\end{matrix}$

As this example shows, the key element position is the second elementposition, the base value is 32, and the inverse of the base value (−33)is written to the key element position of res as described above withrespect to steps 2208-2210). Thus, the elements to the right of the keyelement position in res start at the third element of res. For the thirdelement in res, processor 102 determines the number of relevant elementsfrom the key element position to and including the element in the resultvector. In this case, the number of relevant elements is 2, i.e., thekey element position and the third element in the input vector.Processor 102 then computes a result of inverting the base value twiceinv(inv(32))=32, and writes 32 into the third element of res.

For the fourth element of res, processor 102 determines the number ofrelevant elements is 2, as the key element position, the third elementposition and the fourth element position are from the key elementposition to and including the element in the result vector (and thefourth element does not contribute to the running unary operationbecause pred and cv are not both non-zero). Processor 102 then computesa result of inverting the base value two times inv(inv(32))=32, andwrites 32 into the fourth element of res.

For the fifth element of res, processor 102 determines the number ofrelevant elements is 3, as the key element position, the third elementposition, the fourth element position and the fifth element position arefrom the key element position to and including the element in the resultvector (and the fourth element does not contribute to the running unaryoperation because pred and cv are not both non-zero). Processor 102 thencomputes a result of inverting the base value three timesinv(inv(inv(32)))=−33, and writes −33 into the fifth element of res.

For the sixth element of res, processor 102 determines that this elementis inactive. Since this element, and the eighth element are not set inthis operation, an X is indicated in res.

For the seventh element of res, processor 102 determines the number ofrelevant elements is 4. Processor 102 then computes a result ofinverting the base value four times inv(inv(inv(inv(32))))=32, andwrites 32 into the seventh element of res.

As described above, the RunningInv2P instruction can be used toimplement an efficient running inversion operation, and hence can beused for performing one or more of a vectorized operations or avectorized formula.

RunningNeg1P

FIGS. 23A-23B (collectively, “FIG. 23”) present a flowchart illustratinga process for generating a result vector in accordance with thedescribed embodiments. More specifically, the flowchart in FIG. 23 showsoperations performed for embodiments of the RunningNeg1P instruction. Insome embodiments, the RunningNeg1P instruction can be used to perform anefficient running negation using a cumulative negative operation.

In the described embodiments, the operations shown in FIG. 23 areperformed as part of step 2002 in FIG. 20. Thus, for the purposes ofdescribing the operations shown in FIG. 23, we assume that the inputvector, the control vector, and possibly a predicate vector have beenreceived, as shown in step 2000 in FIG. 20. Additionally, in thefollowing description, the embodiments are described using non-zerovalues, which represent active elements. However, alternativeembodiments are not limited to using non-zero values; any value can beused (zero, positive numbers, chars, TRUE/FALSE, etc.).

Recall that, in the described embodiments, the predicate vector isoptional and hence may not be received. If a predicate vector is notreceived, processor 102 assumes a predicate vector where each elementcontains a non-zero value (and, more generally, an active value) andperforms the operations in FIG. 23 accordingly. In other words, thepredicate vector described below (e.g., with respect to step 2304, etc.)can be an assumed predicate vector.

As shown in FIG. 23, processor 102 first captures a base value containedin an element of the input vector at a key element position (step 2300).In the described embodiments, the key element position is theleftmost/first relevant element in the input vector.

Next, for each of the elements of the result vector in parallel (step2302), processor 102 determines if a corresponding element of thepredicate vector contains a non-zero value (step 2304). If not,processor 102 either leaves unchanged the element in the result vectoror writes a zero in the element of the result vector (step 2306). Forexample, assuming that the input vector (iv1), cv, and pred contain thevalues shown, the result vector (res) could be generated as follows forzeroing:

$\begin{matrix}{{iv}\; 1} & {= \left\{ \begin{matrix}12 & 32 & 64 & 12 & 5 & 19 & 20 & \left. 99 \right\}\end{matrix} \right.} \\{pred} & {= \begin{Bmatrix}0 & 1 & 1 & 1 & 1 & 0 & 1 & 0\end{Bmatrix}} \\{cv} & {= \begin{Bmatrix}0 & 1 & 1 & 0 & 1 & 1 & 1 & 0\end{Bmatrix}} \\{res} & {= \left\{ \begin{matrix}0 & X & X & X & X & 0 & X & \left. 0 \right\}\end{matrix} \right.}\end{matrix}$

In some embodiments, the result vector can include one or more elementsthat contain initial values that were computed during an earlieroperation. Alternatively, the result vector can include one or moreelements that contain initial values that were copied to the resultvector from another vector during the generation of the result vector.The initial values in these elements are the values that are leftunchanged according to predication.

Note that, although we show the negation and the predication/zeroingoperations together in FIG. 23, these operations can occur in separatelyin some embodiments. More specifically, in some embodiments, theoperations shown in steps 2308-2318 in FIG. 23 can be performed in one(parallel) operation to generate a result vector with values forelements in the same locations as elements where predicate vectorcontains a non-zero value. A separate operation can then be performed tocopy the result vector to a destination, with the predication/zeroingshown in steps 2304-2306 being performed during the copy operation. Inthe following description, for clarity and brevity, we describeembodiments where the negation and the predication take place in asingle (parallel) operation.

Processor 102 then determines if the element in the result vector is ata key element position in the result vector (step 2308). If so,processor 102 sets the element in the result vector equal to the basevalue (step 2310). For example, assuming iv1, cv, and pred contain thevalues shown, res could be generated as follows:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & 32 & X & X & X & X & X & X & \}\end{matrix}$

As this example shows, the value of 32 from the key element position ofthe iv1 is written to the key element position of res. For clarity,other elements in res are marked with an X.

Note that a key element position may not exist (i.e., there may be noelement position where both pred[x] and cv[x] contain non-zero values).In such a case, each element in the result vector is set equal to thecorresponding element in the input vector, as is described below withrespect to step 2314.

If the element in the result vector is not at the key element position,processor 102 determines if the element in the result vector is locatedto the left of the key element position in the result vector (step2312). If so, processor 102 sets the element in the result vector equalto a corresponding element in iv1 (step 2314). For example, assumingiv1, cv, and pred contain the values shown, res could be generated asfollows:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & 32 & X & X & X & X & X & X & \}\end{matrix}$

This example shows elements to the left of the key element position forwhich a value from an element iv1[x] has been copied to thecorresponding element of res[x]. For clarity, other elements in res aremarked with an X. As described above, a key element position need notexist in the result vector. In other words, there may be no elementposition in both the predicate vector and the control vector where boththe vectors contain a non-zero value or an active value. (Alternatively,in embodiments where pred[x] is not received, there may be no elementposition where cv[x] contains a non-zero value or an active value.) Ifthis case occurs, the values from iv1 are simply copied to each elementin res where the corresponding element in pred contains a non-zero valueor an active value.

If the element in the result vector is located to the right of the keyelement position (step 2312), processor 102 determines a number ofrelevant elements from the key element position to and including theelement to the left of the element in the result vector (step 2316).Then, processor 102 sets the element in the result vector equal to aresult of performing the negation operation on the base value a numberof times equal to the number of relevant elements (step 2318).

For example, assuming iv1, cv, and pred contain the values shown, rescould be generated as follows (for clarity, elements that are notwritten to during this operation are marked with an X in res.):

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & 32 & {- 32} & 32 & 32 & X & {- 32} & X & \}\end{matrix}$

As this example shows, the key element position is the second elementposition, and the base value is 32 (which is written to the key elementposition of res as described above with respect to steps 2308-2310).Thus, the elements to the right of the key element position in res startat the third element of res. For the third element in res, processor 102determines the number of relevant elements from the key element positionto and including the element to the left of the element in the resultvector (i.e., the third element of the input vector). In this case, thenumber of relevant elements is 1, as the key element position is theonly element position to the left of the third element in the inputvector. Processor 102 then computes a result of negating the base valueonce neg(32)=−32, and writes −32 into the third element of res.

For the fourth element of res, processor 102 determines the number ofrelevant elements is 2, as the key element position and the thirdelement position are to the left of the fourth element in the resultvector. Processor 102 then computes a result of negating the base valuetwice neg(neg(32))=32, and writes 32 into the fourth element of res.

For the fifth element of res, processor 102 determines the number ofrelevant elements is 2, as the key element position, the third elementposition and the fourth element position are to the left of the fifthelement in the result vector (and the fourth element does not contributeto the running unary operation because pred and cv are not bothnon-zero). Processor 102 then computes a result of negating the basevalue twice neg(neg(32))=32, and writes 32 into the fifth element ofres.

For the sixth element of res, processor 102 determines that this elementis inactive. Since this element, and the eighth element, are not set inthis operation, an X is indicated in res.

For the seventh element of res, processor 102 determines the number ofrelevant elements is 3. Processor 102 then computes a result of negatingthe base value three times neg(neg(neg (32)))=32, and writes 32 into theseventh element of res.

As described above, the RunningNeg1P instruction can be used toimplement an efficient running negation operation, and hence can be usedfor performing one or more of a vectorized operations or a vectorizedformula.

RunningNeg2P

FIGS. 24A-24B (collectively, “FIG. 24”) present a flowchart illustratinga process for generating a result vector in accordance with thedescribed embodiments. More specifically, the flowchart in FIG. 24 showsoperations performed for embodiments of the RunningNeg2P instruction. Insome embodiments, the RunningNeg2P instruction can be used to perform anefficient running negation using a cumulative negative operation.

In the described embodiments, the operations shown in FIG. 24 areperformed as part of step 2002 in FIG. 20. Thus, for the purposes ofdescribing the operations shown in FIG. 24, we assume that the inputvector, the control vector, and possibly a predicate vector have beenreceived, as shown in step 2000 in FIG. 20. Additionally, in thefollowing description, the embodiments are described using non-zerovalues, which represent active elements. However, alternativeembodiments are not limited to using non-zero values; any value can beused (zero, positive numbers, chars, TRUE/FALSE, etc.).

Recall that, in the described embodiments, the predicate vector isoptional and hence may not be received. If a predicate vector is notreceived, processor 102 assumes a predicate vector where each elementcontains a non-zero value (and, more generally, an active value) andperforms the operations in FIG. 24 accordingly. In other words, thepredicate vector described below (e.g., with respect to step 2404, etc.)can be an assumed predicate vector.

As shown in FIG. 24, processor 102 first captures a base value containedin an element of the input vector at a key element position (step 2400).In the described embodiments, the key element position is theleftmost/first relevant element in the first input vector.

Next, for each of the elements of the result vector in parallel (step2402), processor 102 determines if a corresponding element of thepredicate vector contains a non-zero value (step 2404). If not,processor 102 either leaves unchanged the element in the result vectoror writes a zero in the element of the result vector (step 2406). Forexample, assuming that the first input vector (iv1), cv, and predcontain the values shown, the result vector (res) could be generated asfollows for zeroing:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & 0 & X & X & X & X & 0 & X & 0 & \}\end{matrix}$

In some embodiments, the result vector can include one or more elementsthat contain initial values that were computed during an earlieroperation. Alternatively, the result vector can include one or moreelements that contain initial values that were copied to the resultvector from another vector during the generation of the result vector.The initial values in these elements are the values that are leftunchanged according to predication.

Note that, although we show the negation and the predication/zeroingoperations together in FIG. 24, these operations can occur in separatelyin some embodiments. More specifically, in some embodiments, theoperations shown in steps 2408-2418 in FIG. 24 can be performed in one(parallel) operation to generate a result vector with values forelements in the same locations as elements where predicate vectorcontains a non-zero value. A separate operation can then be performed tocopy the result vector to a destination, with the predication/zeroingshown in steps 2404-2406 being performed during the copy operation. Inthe following description, for clarity and brevity, we describeembodiments where the division and the predication take place in asingle (parallel) operation.

Processor 102 then determines if the element in the result vector is ata key element position in the result vector (step 2408). If so,processor 102 determines the negative of the base value once and storesthe resulting value at the key element position in the result vector(step 2410). For example, assuming iv1, cv, and pred contain the valuesshown, res could be generated as follows:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & {- 32} & X & X & X & X & X & X & \}\end{matrix}$

For this example, processor 102 first determines a value in the keyelement position in the input vector (i.e., the second element of theinput vector), which is 32. Processor 102 then determines the negativeof 32=−32, and writes −32 into the second element of res. For clarity,other elements in res are marked with an X.

Note that a key element position may not exist (i.e., there may be noelement position where both pred[x] and cv[x] contain non-zero values).In such a case, each element in the result vector is set equal to thecorresponding element in the input vector, as is described below withrespect to step 2414.

If the element in the result vector is not at the key element position,processor 102 determines if the element in the result vector is locatedto the left of the key element position in the result vector (step2412). If so, processor 102 sets the element in the result vector equalto a corresponding element in iv1 (step 2414). For example, assumingiv1, cv, and pred contain the values shown, res could be generated asfollows:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & 32 & X & X & X & X & X & X & \}\end{matrix}$

This example shows elements to the left of the key element position forwhich a value from an element iv1[x] has been copied to thecorresponding element of res[x]. For clarity, other elements in res aremarked with an X. As described above, a key element position need notexist in the result vector. In other words, there may be no elementposition in both the predicate vector and the control vector where boththe vectors contain a non-zero value or an active value. (Alternatively,in embodiments where pred[x] is not received, there may be no elementposition where cv[x] contains a non-zero value or an active value.) Ifthis case occurs, the values from iv1 are simply copied to each elementin res where the corresponding element in pred contains a non-zero valueor an active value.

If the element in the result vector is located to the right of the keyelement position (step 2416), processor 102 determines a number ofrelevant elements from the key element position to and including theelement in the result vector (step 2416). Then, processor 102 sets theelement in the result vector equal to a result of performing thenegative operation on the base value a number of times equal to thenumber of relevant elements (step 2418).

For example, assuming iv1, cv, and pred contain the values shown, rescould be generated as follows (for clarity, elements that are notwritten to during this operation are marked with an X in res.):

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & 0 & {- 32} & 32 & 32 & {- 32} & X & 32 & X & \}\end{matrix}$

As this example shows, the key element position is the second elementposition, the base value is 32, and the negative of the base value (−32)is written to the key element position of res as described above withrespect to steps 2408-2410). Thus, the elements to the right of the keyelement position in res start at the third element of res. For the thirdelement in res, processor 102 determines the number of relevant elementsfrom the key element position to and including the element in the resultvector. In this case, the number of relevant elements is 2, i.e., thekey element position and the third element in the input vector.Processor 102 then computes a result of negating the base value twiceneg(neg(32))=32, and writes 32 into the third element of res.

For the fourth element of res, processor 102 determines the number ofrelevant elements is 2, as the key element position the third elementand the fourth element position are from the key element position to andincluding the element in the result vector (and the fourth element doesnot contribute to the running unary operation because pred and cv arenot both non-zero). Processor 102 then computes a result of negating thebase value two times neg(neg(32))=32, and writes 32 into the fourthelement of res.

For the fifth element of res, processor 102 determines the number ofrelevant elements is 3, and computes a result of negating the base valuethree times neg(neg(neg(32)))=−32, and writes −32 into the fifth elementof res.

For the sixth element of res, processor 102 determines this element isinactive. Since this element, and the eighth element, are not set inthis operation, an X is indicated in res.

For the seventh element of res, processor 102 determines the number ofrelevant elements is 4. Processor 102 then computes a result of negatingthe base value four times neg(neg(neg(neg(32))))=32, and writes 32 intothe seventh element of res.

As described above, the RunningNeg2P instruction can be used toimplement an efficient running negation operation, and hence can be usedfor performing one or more of a vectorized operations or a vectorizedformula.

RunningNot1P

FIGS. 25A-25B (collectively, “FIG. 25”) present a flowchart illustratinga process for generating a result vector in accordance with thedescribed embodiments. More specifically, the flowchart in FIG. 25 showsoperations performed for embodiments of the RunningNot1P instruction. Insome embodiments, the RunningNot1P instruction can be used to perform anefficient running logical NOT using a cumulative logical NOT operation.

In the described embodiments, the operations shown in FIG. 25 areperformed as part of step 2002 in FIG. 20. Thus, for the purposes ofdescribing the operations shown in FIG. 25, we assume that the inputvector, the control vector, and possibly a predicate vector have beenreceived, as shown in step 2000 in FIG. 20. Additionally, in thefollowing description, the embodiments are described using non-zerovalues, which represent active elements. However, alternativeembodiments are not limited to using non-zero values; any value can beused (zero, positive numbers, chars, TRUE/FALSE, etc.).

Recall that, in the described embodiments, the predicate vector isoptional and hence may not be received. If a predicate vector is notreceived, processor 102 assumes a predicate vector where each elementcontains a non-zero value (and, more generally, an active value) andperforms the operations in FIG. 25 accordingly. In other words, thepredicate vector described below (e.g., with respect to step 2504, etc.)can be an assumed predicate vector.

As shown in FIG. 25, processor 102 first captures a base value containedin an element of the input vector at a key element position (step 2500).In the described embodiments, the key element position is theleftmost/first relevant element in the input vector.

Next, for each of the elements of the result vector in parallel (step2502), processor 102 determines if a corresponding element of thepredicate vector contains a non-zero value (step 2504). If not,processor 102 either leaves unchanged the element in the result vectoror writes a zero in the element of the result vector (step 2506). Forexample, assuming that the input vector (iv1), cv, and pred contain thevalues shown, the result vector (res) could be generated as follows forzeroing:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & 0 & X & X & X & X & 0 & X & 0 & \}\end{matrix}$

In some embodiments, the result vector can include one or more elementsthat contain initial values that were computed during an earlieroperation. Alternatively, the result vector can include one or moreelements that contain initial values that were copied to the resultvector from another vector during the generation of the result vector.The initial values in these elements are the values that are leftunchanged according to predication.

Note that, although we show the logical NOT and the predication/zeroingoperations together in FIG. 25, these operations can occur in separatelyin some embodiments. More specifically, in some embodiments, theoperations shown in steps 2508-2518 in FIG. 25 can be performed in one(parallel) operation to generate a result vector with values forelements in the same locations as elements where predicate vectorcontains a non-zero value. A separate operation can then be performed tocopy the result vector to a destination, with the predication/zeroingshown in steps 2504-2506 being performed during the copy operation. Inthe following description, for clarity and brevity, we describeembodiments where the logical NOT and the predication take place in asingle (parallel) operation.

Processor 102 then determines if the element in the result vector is ata key element position in the result vector (step 2508). If so,processor 102 sets the element in the result vector equal to the basevalue (step 2510). For example, assuming iv1, cv, and pred contain thevalues shown, res could be generated as follows:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & 32 & X & X & X & X & X & X & \}\end{matrix}$

As this example shows, the value of 32 from the key element position ofthe iv1 is written to the key element position of res. For clarity,other elements in res are marked with an X.

Note that a key element position may not exist (i.e., there may be noelement position where both pred[x] and cv[x] contain non-zero values).In such a case, each element in the result vector is set equal to thecorresponding element in the input vector, as is described below withrespect to step 2514.

If the element in the result vector is not at the key element position,processor 102 determines if the element in the result vector is locatedto the left of the key element position in the result vector (step2512). If so, processor 102 sets the element in the result vector equalto a corresponding element in iv1 (step 2514). For example, assumingiv1, cv, and pred contain the values shown, res could be generated asfollows:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & 32 & X & X & X & X & X & X & \}\end{matrix}$

This example shows elements to the left of the key element position forwhich a value from an element iv1[x] has been copied to thecorresponding element of res[x]. For clarity, other elements in res aremarked with an X. As described above, a key element position need notexist in the result vector. In other words, there may be no elementposition in both the predicate vector and the control vector where boththe vectors contain a non-zero value or an active value. (Alternatively,in embodiments where pred[x] is not received, there may be no elementposition where cv[x] contains a non-zero value or an active value.) Ifthis case occurs, the values from iv1 are simply copied to each elementin res where the corresponding element in pred contains a non-zero valueor an active value.

If the element in the result vector is located to the right of the keyelement position (step 2512), processor 102 determines a number ofrelevant elements from the key element position to and including theelement to the left of the element in the result vector (step 2516).Then, processor 102 sets the element in the result vector equal to aresult of performing the logical NOT operation on the base value anumber of times equal to the number of relevant elements (step 2518).

For example, assuming iv1, cv, and pred contain the values shown, rescould be generated as follows (for clarity, elements that are notwritten to during this operation are marked with an X in res.):

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & 32 & 0 & 1 & 1 & X & 0 & X & \}\end{matrix}$

As this example shows, the key element position is the second elementposition, and the base value is 32 (which is written to the key elementposition of res as described above with respect to steps 2508-2510).Thus, the elements to the right of the key element position in res startat the third element of res. For the third element in res, processor 102determines the number of relevant elements from the key element positionto and including the element to the left of the element in the resultvector (i.e., the third element of the input vector). In this case, thenumber of relevant elements is 1, as the key element position is theonly element position to the left of the third element in the inputvector. Processor 102 then computes a result of performing a NOToperation on the base value once NOT(32)=0 (note that the logical NOT ofany non-zero value is 0, and the logical NOT of 0 is 1), and writes 0into the third element of res.

For the fourth element of res, processor 102 determines the number ofrelevant elements is 2, as the key element position and the thirdelement position are to the left of the fourth element in the inputvector. Processor 102 then computes a result of performing a NOToperation on the base value twice NOT(NOT(32))=1, and writes 1 into thefourth element of res.

For the fifth element of res, processor 102 determines the number ofrelevant elements is 2, as the key element position, the third elementposition and the fourth element position are to the left of the fourthelement in the result vector (and the fourth element does not contributeto the running unary operation because pred and cv are not bothnon-zero). Processor 102 then computes a result of performing a NOToperation on the base value twice NOT(NOT(32))=1, and writes 1 into thefifth element of res.

For the sixth element of res, processor 102 determines that this elementis inactive. Since this element, and the eighth element, are not set inthis operation, an X is indicated in res.

For the seventh element of res, processor 102 determines the number ofrelevant elements is 3. Processor 102 then computes a result ofperforming a NOT operation on the base value three times NOT(NOT(NOT(32)))=0, and writes 0 into the seventh element of res.

As described above, the RunningNot1P instruction can be used toimplement an efficient running logical NOT operation, and hence can beused for performing one or more of a vectorized operations or avectorized formula.

RunningNot2P

FIGS. 26A-26B (collectively, “FIG. 26”) present a flowchart illustratinga process for generating a result vector in accordance with thedescribed embodiments. More specifically, the flowchart in FIG. 26 showsoperations performed for embodiments of the RunningNot2P instruction. Insome embodiments, the RunningNot2P instruction can be used to perform anefficient running logical NOT using a cumulative logical NOT operation.

In the described embodiments, the operations shown in FIG. 26 areperformed as part of step 2002 in FIG. 20. Thus, for the purposes ofdescribing the operations shown in FIG. 26, we assume that the inputvector, the control vector, and possibly a predicate vector have beenreceived, as shown in step 2000 in FIG. 20. Additionally, in thefollowing description, the embodiments are described using non-zerovalues, which represent active elements. However, alternativeembodiments are not limited to using non-zero values; any value can beused (zero, positive numbers, chars, TRUE/FALSE, etc.).

Recall that, in the described embodiments, the predicate vector isoptional and hence may not be received. If a predicate vector is notreceived, processor 102 assumes a predicate vector where each elementcontains a non-zero value (and, more generally, an active value) andperforms the operations in FIG. 26 accordingly. In other words, thepredicate vector described below (e.g., with respect to step 2604, etc.)can be an assumed predicate vector.

As shown in FIG. 26, processor 102 first captures a base value containedin an element of the input vector at a key element position (step 2600).In the described embodiments, the key element position is theleftmost/first relevant element in the first input vector.

Next, for each of the elements of the result vector in parallel (step2602), processor 102 determines if a corresponding element of thepredicate vector contains a non-zero value (step 2604). If not,processor 102 either leaves unchanged the element in the result vectoror writes a zero in the element of the result vector (step 2606). Forexample, assuming that the first input vector (iv1), cv, and predcontain the values shown, the result vector (res) could be generated asfollows for zeroing:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & 0 & X & X & X & X & 0 & X & 0 & \}\end{matrix}$

In some embodiments, the result vector can include one or more elementsthat contain initial values that were computed during an earlieroperation. Alternatively, the result vector can include one or moreelements that contain initial values that were copied to the resultvector from another vector during the generation of the result vector.The initial values in these elements are the values that are leftunchanged according to predication.

Note that, although we show the logical NOT and the predication/zeroingoperations together in FIG. 26, these operations can occur in separatelyin some embodiments. More specifically, in some embodiments, theoperations shown in steps 2608-2618 in FIG. 26 can be performed in one(parallel) operation to generate a result vector with values forelements in the same locations as elements where predicate vectorcontains a non-zero value. A separate operation can then be performed tocopy the result vector to a destination, with the predication/zeroingshown in steps 2604-2606 being performed during the copy operation. Inthe following description, for clarity and brevity, we describeembodiments where the division and the predication take place in asingle (parallel) operation.

Processor 102 then determines if the element in the result vector is ata key element position in the result vector (step 2608). If so,processor 102 determines the logical NOT of the base value once andstores the resulting value at the key element position in the resultvector (step 2610). For example, assuming iv1, cv, and pred contain thevalues shown, res could be generated as follows:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & 0 & X & X & X & X & X & X & \}\end{matrix}$

For this example, processor 102 first determines a value in the keyelement position in the input vector (i.e., the second element of theinput vector), which is 32. Processor 102 then determines the logicalNOT of 32=0 (note, once again, that the logical NOT of any non-zerovalue is 0, and the logical NOT of 0 is 1), and writes 0 into the secondelement of res. For clarity, other elements in res are marked with an X.

Note that a key element position may not exist (i.e., there may be noelement position where both pred[x] and cv[x] contain non-zero values).In such a case, each element in the result vector is set equal to thecorresponding element in the input vector, as is described below withrespect to step 2614.

If the element in the result vector is not at the key element position,processor 102 determines if the element in the result vector is locatedto the left of the key element position in the result vector (step2612). If so, processor 102 sets the element in the result vector equalto a corresponding element in iv1 (step 2614). For example, assumingiv1, cv, and pred contain the values shown, res could be generated asfollows:

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 0 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & 32 & X & X & X & X & X & X & \}\end{matrix}$

This example shows elements to the left of the key element position forwhich a value from an element iv1[x] has been copied to thecorresponding element of res[x]. For clarity, other elements in res aremarked with an X. As described above, a key element position need notexist in the result vector. In other words, there may be no elementposition in both the predicate vector and the control vector where boththe vectors contain a non-zero value or an active value. (Alternatively,in embodiments where pred[x] is not received, there may be no elementposition where cv[x] contains a non-zero value or an active value.) Ifthis case occurs, the values from iv1 are simply copied to each elementin res where the corresponding element in pred contains a non-zero valueor an active value.

If the element in the result vector is located to the right of the keyelement position (step 2616), processor 102 determines a number ofrelevant elements from the key element position to and including theelement in the result vector (step 2616). Then, processor 102 sets theelement in the result vector equal to a result of performing the logicalNOT operation on the base value a number of times equal to the number ofrelevant elements (step 2618).

For example, assuming iv1, cv, and pred contain the values shown, rescould be generated as follows (for clarity, elements that are notwritten to during this operation are marked with an X in res.):

$\begin{matrix}{{iv}\; 1} & = & \{ & 12 & 32 & 64 & 12 & 5 & 19 & 20 & 99 & \} \\{pred} & = & \{ & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & \} \\{cv} & = & \{ & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & \} \\{res} & = & \{ & X & 0 & 1 & 1 & 0 & X & 1 & X & \}\end{matrix}$

As this example shows, the key element position is the second elementposition, the base value is 32, and the logical NOT of the base value(0) is written to the key element position of res as described abovewith respect to steps 2608-2610). Thus, the elements to the right of thekey element position in res start at the third element of res. For thethird element in res, processor 102 determines the number of relevantelements from the key element position to and including the element inthe result vector. In this case, the number of relevant elements is 2,i.e., the key element position and the third element in the inputvector. Processor 102 then computes a result of performing a NOToperation on the base value twice NOT(NOT(32)), and writes 1 into thethird element of res.

For the fourth element of res, processor 102 determines the number ofrelevant elements is 2, as the key element position, the third elementand the fourth element position are from the key element position to andincluding the element in the result vector (and the fourth element doesnot contribute to the running unary operation because pred and cv arenot both non-zero). Processor 102 then computes a result of performing aNOT operation on the base value twice NOT(NOT(32)), and writes 1 intothe fourth element of res.

For the fifth element of res, processor 102 determines the number ofrelevant elements is 3. Processor 102 then computes a result ofperforming a NOT operation on the base value three timesNOT(NOT(NOT(32))), and writes 0 into the fifth element of res

For the sixth element of res, processor 102 determines that this elementis inactive. Since this element, and the eighth element, are not set inthis operation, an X is indicated in res.

For the seventh element of res, processor 102 determines the number ofrelevant elements is 4. Processor 102 then computes a result ofperforming a NOT operation on the base value four timesNOT(NOT(NOT(NOT(88))))=1, and writes 1 into the seventh element of res.

As described above, the RunningNot2P instruction can be used toimplement an efficient running logical NOT operation, and hence can beused for performing one or more of a vectorized operations or avectorized formula.

The foregoing descriptions have been presented only for purposes ofillustration and description. They are not intended to be exhaustive orto limit the described embodiments to the forms disclosed. Accordingly,many modifications and variations will be apparent to practitionersskilled in the art. Additionally, the above disclosure is not intendedto limit the described embodiments. The scope of these embodiments isdefined by the appended claims.

1. A method for generating a result vector, comprising: receiving aninput vector, a control vector, and optionally receiving a predicatevector, wherein each vector includes N elements; recording a base valuefrom an element at a key element position in the input vector; andgenerating the result vector, wherein generating the result vectorcomprises, if the predicate vector is received, for each active elementin the result vector to the right of the key element position,otherwise, for each element in the result vector to the right of the keyelement position, determining a number of relevant elements from the keyelement position to and including a predetermined element in the resultvector; and setting the element in the result vector equal to a resultof performing a unary operation on the base value a number of timesequal to the number of relevant elements.
 2. The method of claim 1,wherein the unary operation includes one of: a bitwise inversion,negation, and a logical NOT.
 3. The method of claim 1, whereingenerating the result vector comprises setting the element in the resultvector at the key element position equal to one of: the base value; or aresult of performing the unary operation on the base value once.
 4. Themethod of claim 1, wherein the predetermined element in the resultvector is one of: a first element to the left of the element in theresult vector; or the element in the result vector.
 5. The method ofclaim 1, wherein, if the predicate vector is received, the key elementposition is a leftmost element position where both the control vectorand the predicate vector are active; otherwise, the key element positionis a leftmost active element in the control vector.
 6. The method ofclaim 1, wherein, if the predicate vector is received, for each elementin the result vector to the left of the key element position for which acorresponding element in the predicate vector is active, otherwise, foreach element in the result vector to the left of the key elementposition in the result vector, generating the result vector comprisessetting the element in the result vector equal to a value in acorresponding element in the input vector; and wherein, if no keyelement position exists, and if the predicate vector is received, foreach element in the result vector for which a corresponding element inthe predicate vector is active, otherwise, for each element in theresult vector, generating the result vector comprises setting eachelement in the result vector equal to a value in a corresponding elementin the input vector.
 7. The method of claim 1, wherein, if the predicatevector is received, generating the result vector comprises, for eachelement in the result vector, if a corresponding element in thepredicate vector is inactive, one of: leaving the element in the resultvector unmodified; or setting the element in the result vector to zero.8. The method of claim 1, wherein generating the result vector comprisesprocessing elements in the input vector, the control vector, and, if thepredicate vector is received, the predicate vector in parallel to enablethe elements of the result vector to be generated in parallel.
 9. Themethod of claim 1, wherein, if the predicate vector is received, arelevant element in the result vector is an element in the result vectorfor which the corresponding element in the predicate vector and thecorresponding element in the control vector are active; otherwise, arelevant element in the result vector is an element in the result vectorfor which the corresponding element in the control vector is active. 10.A processor for generating a result vector, comprising: an executionmechanism in the processor, wherein the execution mechanism isconfigured to: receive an input vector, a control vector, and optionallyreceiving a predicate vector, wherein each vector includes N elements;record a base value from an element at a key element position in theinput vector; and generate the result vector, wherein generating theresult vector comprises, if the predicate vector is received, for eachactive element in the result vector to the right of the key elementposition, otherwise, for each element in the result vector to the rightof the key element position, determining a number of relevant elementsfrom the key element position to and including a predetermined elementin the result vector; and setting the element in the result vector equalto a result of performing a unary operation on the base value a numberof times equal to the number of relevant elements.
 11. The processor ofclaim 10, wherein the unary operation includes one of: a bitwiseinversion, negation, and a logical NOT.
 12. The processor of claim 10,wherein generating the result vector comprises setting the element inthe result vector at the key element position equal to one of: the basevalue; or a result of performing the unary operation on the base valueonce.
 13. The processor of claim 10, wherein the predetermined elementin the result vector is one of: a first element to the left of theelement in the result vector; or the element in the result vector. 14.The processor of claim 10, wherein, if the predicate vector is received,the key element position is a leftmost element position where both thecontrol vector and the predicate vector are active; otherwise, the keyelement position is a leftmost active element in the control vector. 15.The processor of claim 10, wherein, if the predicate vector is received,for each element in the result vector to the left of the key elementposition for which a corresponding element in the predicate vector isactive, otherwise, for each element in the result vector to the left ofthe key element position in the result vector, when generating theresult vector the execution mechanism is configured to set the elementin the result vector equal to a value in a corresponding element in theinput vector; and wherein, if no key element position exists, and if thepredicate vector is received, for each element in the result vector forwhich a corresponding element in the predicate vector is active,otherwise, for each element in the result vector, when generating theresult vector the execution mechanism is configured to set each elementin the result vector equal to a value in a corresponding element in theinput vector.
 16. The processor of claim 10, wherein, if the predicatevector is received, when generating the result vector, for each elementin the result vector, if a corresponding element in the predicate vectoris inactive, the execution mechanism is configured to one of: leavingthe element in the result vector unmodified; or setting the element inthe result vector to zero.
 17. The processor of claim 10, wherein whengenerating the result vector, the execution mechanism is configured toprocess elements in the input vector, the control vector, and, if thepredicate vector is received, the predicate vector in parallel to enablethe elements of the result vector to be generated in parallel.
 18. Theprocessor of claim 10, wherein, if the predicate vector is received, arelevant element in the result vector is an element in the result vectorfor which the corresponding element in the predicate vector and thecorresponding element in the control vector are active; otherwise, arelevant element in the result vector is an element in the result vectorfor which the corresponding element in the control vector is active. 19.A computer system for generating a result vector, comprising: aprocessor; a memory coupled to the processor, wherein the memory storesinstructions and data for the processor; and at least one execution unitin the processor, wherein the execution unit is configured to: receivean input vector, a control vector, and optionally receiving a predicatevector, wherein each vector includes N elements; record a base valuefrom an element at a key element position in the input vector; andgenerate the result vector, wherein generating the result vectorcomprises, if the predicate vector is received, for each active elementin the result vector to the right of the key element position,otherwise, for each element in the result vector to the right of the keyelement position, determining a number of relevant elements from the keyelement position to and including a predetermined element in the resultvector; and setting the element in the result vector equal to a resultof performing a unary operation on the base value a number of timesequal to the number of relevant elements.
 20. The system of claim 19,wherein the unary operation includes one of: a bitwise inversion,negation, and a logical NOT.
 21. The system of claim 19, whereingenerating the result vector comprises setting the element in the resultvector at the key element position equal to one of: the base value; or aresult of performing the unary operation on the base value once.
 22. Thesystem of claim 19, wherein the predetermined element in the resultvector is one of: a first element to the left of the element in theresult vector; or the element in the result vector.
 23. The system ofclaim 19, wherein, if the predicate vector is received, the key elementposition is a leftmost element position where both the control vectorand the predicate vector are active; otherwise, the key element positionis a leftmost active element in the control vector.
 24. The system ofclaim 19, wherein, if the predicate vector is received, for each elementin the result vector to the left of the key element position for which acorresponding element in the predicate vector is active, otherwise, foreach element in the result vector to the left of the key elementposition in the result vector, when generating the result vector theexecution unit is configured to set the element in the result vectorequal to a value in a corresponding element in the input vector; andwherein, if no key element position exists, and if the predicate vectoris received, for each element in the result vector for which acorresponding element in the predicate vector is active, otherwise, foreach element in the result vector, when generating the result vector theexecution unit is configured to set each element in the result vectorequal to a value in a corresponding element in the input vector.
 25. Thesystem of claim 19, wherein, if the predicate vector is received, whengenerating the result vector, for each element in the result vector, ifa corresponding element in the predicate vector is inactive, theexecution unit is configured to one of: leaving the element in theresult vector unmodified; or setting the element in the result vector tozero.
 26. The system of claim 19, wherein when generating the resultvector, the execution mechanism is configured to process elements in theinput vector, the control vector, and, if the predicate vector isreceived, the predicate vector in parallel to enable the elements of theresult vector to be generated in parallel.
 27. The system of claim 19,wherein, if the predicate vector is received, a relevant element in theresult vector is an element in the result vector for which thecorresponding element in the predicate vector and the correspondingelement in the control vector are active; otherwise, a relevant elementin the result vector is an element in the result vector for which thecorresponding element in the control vector is active.